Open OliverJAsh opened 4 years ago
This isn't a TypeScript thing, import()
is a language feature, dynamic import. That it's in type-space is unrelated.
Dynamic imports aren't usually checked, because they aren't forced to be static, and it's impossible to reliably statically know the import path.
Good point.
Dynamic imports aren't usually checked, because they aren't forced to be static, and it's impossible to reliably statically know the import path.
When using them at the type-level, they are required to be static, so it does makes sense to lint them in this context.
At that point tho, doesn't typescript itself warn on it?
Why would TS warn about this?
type Api = typeof import('../app/helpers/api');
The module path is valid. It's just we want to disallow it, via no-restricted-paths
.
ahhh gotcha, thanks for clarifying.
I am feeling free to ask for an additional parameter for each zone.
Is it possible to allow typescript special imports for types?
import type {MyType} from "/normally/forbidden/import/in/restricted/area"
It would be nice to disallow imports which stay in compiled javascript but allow imports of type in this way.
The parameter for the zone could be named as "allowTypeImports": true
None of these run any code so they should be allowed:
import "/normally/forbidden/import/in/restricted/area" // if the file is d.ts, but rare
import {MyType} from "/normally/forbidden/import/in/restricted/area"
import {type MyType} from "/normally/forbidden/import/in/restricted/area"
import type {MyType} from "/normally/forbidden/import/in/restricted/area"
type MyType = typeof import("/normally/forbidden/import/in/restricted/area");
Docs on
import
types: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-typesReduced test case (all dependencies are latest):