Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are import aliases possible using Typescript

Today I am using import aliasing to change the name of an import in React:

import { Something as SomethingElse } from 'somewhere';

However, after switching this file over to TypeScript, the same thing doesn't seem possible. Only after removing the alias am I able to use the import:

import Something from 'somewhere';

Is it possible to use an import alias in TypeScript?

like image 546
arctic Avatar asked Nov 17 '25 06:11

arctic


1 Answers

That's a default export, so you could just name it whatever you want:

import SomethingElse from 'somewhere';

These default exports are written like:

export default ...

and you can check out some other explanations here.

You may also be interested in the options allowSyntheticDefaultImports and esModuleInterop if you can't get it to work.

like image 84
catgirlkelly Avatar answered Nov 18 '25 20:11

catgirlkelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!