Home > Mobile >  exporting Typescript interface / vs-code complains, but tsc is fine
exporting Typescript interface / vs-code complains, but tsc is fine

Time:11-05

If writing this in a create-react-app project then VS-Code complains about the last line export { MyInterface}

// test.ts

interface MyInterface {
  bazz(): void;
}

export { MyInterface }    

This Error apears only in VS-Code - the typescript-compiler is fine

 Re-exporting a type when the '--isolatedModules' flag is provided 
 requires using 'export type'.ts(1205)
 -----------------------------
 (alias) interface MyInterface
 export MyInterface

CodePudding user response:

The error message tells you everything.

Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.ts(1205)

If you have that compiler flag enabled, then you just need to change export to export type and works as you expect:

export type { MyInterface };

Code Sandbox


According to the docs:

Setting the isolatedModules flag tells TypeScript to warn you if you write certain code that can’t be correctly interpreted by a single-file transpilation process.

It does not change the behavior of your code, or otherwise change the behavior of TypeScript’s checking and emitting process.

This flag forces you to be more explicit about exports. So you just have to tell typescript this export is for sure not meant to exist at runtime via export type.

  • Related