Does Webstorm support typescript path alias?

I'm using Webstorm 3.0 EAP and I want to use typescript path alias feature after reading this introduction: 

https://netbasal.com/sexier-imports-in-typescript-e3c645bdd3c6

tsconfig.json:

{
"baseUrl": "./",
"paths": {
"@baseImages/*": ["images/*"]
}
}

When I import the module like this in a tsx file:


import * as Images from "@baseImages"

 

Webstorm always says unable to `find the module @baseImages`. Does it support path alias?

1 comment

WebStorm 2018.3 definitely does support Typescript path mappings. But your mappings are wrong - you will see the same error when running tsc in terminal:

tsc -p .
app.ts:1:25 - error TS2307: Cannot find module '@baseImages'.

1 import * as Images from "@baseImages"
                          ~~~~~~~~~~~~~

you just can't use barrel import from path that exactly matches the specified name prefix when using wildcards.. Adding one more path mapping seems to the the only way to go:

"baseUrl": "./",
"paths": {
"@baseImages/*": ["images/*"],
"@baseImages": ["images/"]
}

see https://github.com/Microsoft/TypeScript/issues/26859, https://github.com/Microsoft/TypeScript/issues/27579

0

Please sign in to leave a comment.