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
Module exports are the instructions that tell Node. js which bits of code (functions, objects, strings, etc.) to export from a given file so that other files are allowed to access the exported code.
When we want to export a single class/variable/function from one module to another module, we use the module. exports way. When we want to export multiple variables/functions from one module to another, we use exports way.
When you export a module, you can import it into other parts of your applications and consume it. Node. js supports CommonJS Modules and ECMAScript Modules.
Can't import the named Export children from non EcmaScript module only default export is available? Solution: You Just need to Downgrade the Framer motion version to “4.1. 17” in your package. json file and then run npm install Now, Your error must be solved.
From https://devblogs.microsoft.com/typescript/announcing-typescript-3-8-beta/:
As a solution in TypeScript 3.8, we’ve added a new syntax for type-only imports and exports.
import type { SomeThing } from "./some-module.js";
export type { SomeThing };
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With