New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[plugin-transform-typescript] Default or named exported interface result in runtime error #7640
Comments
Hey @ThaNarie! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Related: #7118 |
@nicolo-ribaudo I noticed you changed the topic to include |
…rface. See babel#7118 and babel#7640 for details. [skip ci]
…rface. See babel#7118 and babel#7640 for details. [skip ci]
btw this also doesn't work export { IProps as IComponentProps } |
Not sure if what I'm seeing is related or a separate bug, but I experience the same behavior when there is anything else but an exported interface in the file (but I'm not re-exporting imported interfaces). For example: interface A {}
export default A; works fine, but: export const a = () => {};
interface A {}
export default A; gives me a runtime error. Note: I haven't tested the above in particular, but my cases are just as trivial. |
I'm getting this as a compile time error: |
There is an open PR for that error. |
I've updated
to the latest versions and code below stopped working with type MyType = { field: string };
export { MyType };
Where I can see it? |
Oh, it breaks even if I do |
It's #9766. Sorry if I forgot to link it! |
@nicolo-ribaudo The named exports are fixed but the default export is still broken in v7.4.5. Please reopen this issue. |
cc @airato do you want to take a look at this again? |
Yes, I'll take a look |
Input Code
Babel/Babylon Configuration (.babelrc, package.json, cli command)
Expected Behavior
Either:
Current Behavior
TS compilation results in:
Which results in the runtime error:
Possible Solution
When stripping interfaces (or probably any non-value types), either:
Context
I'm using and re-exporting interfaces in my node modules' 'index.ts' file, so you can use them in other TypeScript projects, e.g.:
When publishing the package, the
tsc
also runs to generated.ts
files, which makes the code above work in a TS project (babel strips types and generates JS code, tsc generates the definitions).Workaround
A workaround is to use named exports, since the faulty generated code only happens when using default exports.
When using a named export, the export itself will be removed along with the interface, since it's a single statement. The (now empty) file will be imported somewhere, but will just result in an undefined value. This shouldn't matter, since Interfaces themselves are not used at runtime.
Your Environment
Related
Different but related to #7118 (where that's a syntax/parsing error, while this current issue is a runtime error)
Edit by @nicolo-ribaudo
This also doesn't work with
export { interface }
(#7641) - replThe text was updated successfully, but these errors were encountered: