--isolatedModules, re-export
Provide guidance to the user on what to do when they hit the "Cannot re-export a type when the '--isolatedModules' flag is provided" error message in cases like this:
export { Foo } from "./mod";
As-is, the error message:
Here are some options for fixing:
export type Foo = import('./mod').Fooimport { Foo as FooAlias } from "./mod"; export type Foo = FooAlias;"Currently, we've seen that users don't know what action to take when they hit this error message. Adding this additional information will provide clear guidance to the user on the preferred workaround.
Code:
export { Foo } from "./mod";
Full error message:
" Try rewriting as export type Foo = import('./mod').Foo. Reason: When the '--isolatedModules' flag is provided, TS must be able to distinguish types and values by looking at only the current file.`
My suggestion meets these guidelines:
I feel like the right answer is to just make a Stack Overflow Q&A about this with more examples and explanation. The error message is very to-the-point and we don't typically dive super deep into the "why" or "what else should I do" unless we can deliver a one-line alternative.
Thanks for explaining.
Isn't the current error message incorrect, though? It says that re-exporting a type isn't permitted. But re-exporting a type is permitted, provided the user aliases or uses different syntax.
@mheiber I agree that this is a misleading error message. At the very least it should say Cannot export unaliased types when '--isolatedModules' flag is provided. That would at the very least give you the hint about aliasing.
We shouldn't have to go to SO just to decipher what every esoteric message typescript provides means when there are useful and friendly alternatives. It makes the language very inaccessible.
In TS 3.8 the message is Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'., so this issue can be closed?
In TS 3.8 the message is
Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'., so this issue can be closed?
馃憤 thanks for the reminder, @vkrol