-
Notifications
You must be signed in to change notification settings - Fork 69
const enums not supported in some transpilers #323
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Never mind, seems to be an issue with |
Maybe this can refactored from enum to const as const approach? const Versions = {
V03: 3,
} as const |
Hi @moltar - I am unable to reproduce this. I tried downloading the export var Version;
(function(Version1) {
Version1["V1"] = "1.0";
Version1["V03"] = "0.3";
})(Version || (Version = {
})); Can you provide some steps to reproduce this? |
Here is a repro: https://github.com/moltar/cloudevent-exp |
Thanks @moltar. This really seems to be an issue with swc. By modifying your example to use ts-jest instead of swc the example runs without error.
My modifications.
diff --git a/package.json b/package.json
index 2342abf..fa3a0b7 100644
--- a/package.json
+++ b/package.json
@@ -11,10 +11,12 @@
"license": "ISC",
"dependencies": {
"@swc-node/jest": "0.1.27",
- "cloudevent": "0.6.0",
"cloudevents": "3.1.0",
"jest": "26.4.2",
- "ts-jest": "26.3.0",
- "typescript": "4.0.2"
+ "typescript": "^4.0.2"
+ },
+ "devDependencies": {
+ "@types/jest": "^26.0.12",
+ "ts-jest": "^26.3.0"
}
}
diff --git a/jest.config.js b/jest.config.js
index 0bda6ad..91a2d2c 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -1,11 +1,4 @@
module.exports = {
+ preset: 'ts-jest',
testEnvironment: 'node',
-
- // config for ts-jest
- // preset: 'ts-jest',
-
- // config for @swc-node/jest
- transform: {
- '^.+\\.(t|j)sx?$': ['@swc-node/jest'],
- },
}; |
It is an issue with SWC, and they did confirm it in the linked issue: swc-project/swc#940 But this is also a larger issue, because Babel also does not support const enums: babel/babel#8741 I don't use babel, but there is a large portion of TS users who do. Here is a short explainer (not my article): https://ncjamieson.com/dont-export-const-enums/ |
This issue is stale because it has been open 30 days with no activity. |
Not stale |
This issue is stale because it has been open 30 days with no activity. |
@moltar I see your point to some degree (though the blog post you linked is 404), which is why we have modified the bot to never actually close an issue. But having the label is useful, imo. |
This issue is stale because it has been open 30 days with no activity. |
Describe the Bug
Version
appears to beundefined
.Steps to Reproduce
Expected Behavior
Version should be defined.
Additional context
Using package from NPM version
3.1.0
.The text was updated successfully, but these errors were encountered: