-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cannot import declared enum #1253
Comments
In your example, the TypeScript compiler (i.e. running
So there is no enum to import, and the generated code will crash at run-time. What are you trying to do? What is the use case? Is there a use case for getting a run-time crash instead of a compile-time error? Since esbuild doesn't have a type system, the Files are compiled one-at-a-time so esbuild requires TypeScript's |
Thanks fore the detailed answer @evanw! Admittedly I might be using this wrong. The confusion comes from the fact that |
Can you provide instructions for how to compile the code in your original post correctly? I will be able to understand this better if I can reproduce it myself. I tried to reproduce this by setting up a React Native TypeScript project (https://reactnative.dev/docs/typescript), adding the code from your original post to the template, and running
The contents of export declare enum MyEnum {
valueOne,
valueTwo
} So it seems like React Native doesn't support this either? |
Thanks a lot for pointing this out @evanw! I created a Snack here https://snack.expo.io/Lg8tSfY3e to demonstrate this (refer to I believe the main takeaway of this is that ESBuild shouldn't parse |
I think I'm going to close this issue because it sounds like esbuild is doing the right thing here. The behavior is a little different than TypeScript in that the error happens at compile-time instead of run-time, but that seems better to me. I'd rather know about bundle linkage failures at compile-time in this case. |
This breaks esbuild (evanw/esbuild#1253). We should probably move these to non-const in js-debug-browser.
@evanw Problems occur when the code written in the library, not the code I wrote, is compiled. |
updating the tsconfig works for me without doing anything else ! "compilerOptions": {
"lib": ["ES2015", "ESNext", "DOM"],
"outDir": "./dist",
"rootDir": "./src",
"types": ["jest", "node"],
"module": "ES6",
"target": "ES6",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
}, in the exporting module |
Importing exported enums from a seperate file doesn't seem to work. You can still use the enum within the same file though. For example:
src/constants/index.ts
src/index.ts
Result:
Workaround?
Exporting the enum as a const works:
The text was updated successfully, but these errors were encountered: