Export not found on module

PlayMa256 picture PlayMa256 · Sep 10, 2018 · Viewed 7.1k times · Source

I have a library, in one of the files i export an interface:

export interface MyInterface {
...
}

and there is a default export, which is a react component.

On an index.ts file, I import few stuff, and re-export them:

import Something from "./Something";
import OtherStuff from "./OtherStuff";
import ExportDefault, { MyInterface } from "./QuestionFile";

export { Something, OtherStuff, ExportDefault, MyInterface };

When I compile, I get an error:

MyInterface is not exported by QuestionFile.

My goal is, whoever imports my library is able to import that type definition to use too.

Is there a better way to do that?

if I do:

export * from "./QuestionFile"

it works, otherwise it breaks my build.

An example on what is going on can be found on this repository: https://github.com/PlayMa256/typescript-babel-error

Answer

Matt McCutchen picture Matt McCutchen · Sep 10, 2018

Re-exporting types is one of the known TypeScript constructs that don't work when using Babel to compile TypeScript because they require cross-file information. You can enable the isolatedModules TypeScript compiler option to report these constructs as errors when you compile with tsc (not Babel) or use the TypeScript language service in an IDE. export * is one workaround; another described in this issue is to use a type alias instead of a re-export. Yet another workaround is to merge a constant with the interface. (It's a hack but avoids some of the disadvantages of the other approaches.)

export interface testInterface {
    name?: string;
}
export const testInterface = undefined;