-
Notifications
You must be signed in to change notification settings - Fork 454
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
[Question]Const enum still not working #944
Comments
Encountered exact same issue with enums, also with the latest "ts-jest" package. The work around for this was to put enum in separate file after that it was correctly transpiled. |
@riston I just went for the workaround of let enum: enum.propertyOfEnum = numberOfEnum as enum.propertyOfEnum; |
Thanks for the awesome repo, I'm facing the same issue and not even the workaround mentioned by @riston is working for me. |
@riston I've tried your workaround, but it's only work as a default export. The enum is correctly transpiled if it is in the same file. It looks like the enum will be loaded only after interpreting the file, when a named import is used. Examples:
enum langauges {
DE = "de-DE",
EN = "en-EN"
}
console.log(langauges);
export {langauges}
import {languages} from './file1'
const translations = {
[languages.DE]: { }
} Error: Cannot read property "DE" of undefined
enum langauges {
DE = "de-DE",
EN = "en-EN"
}
console.log(langauges);
export default langauges
import languages from './file1'
const translations = {
[languages.DE]: { }
} no errors |
I also had to research a lot why my test files were throwing a type error when importing and using a constant enum. While removing the |
Tried using the plugin https://github.com/dosentmatter/babel-plugin-const-enum but haven't had any luck there either (though I may be missing something in setting it up?) |
|
My solution was to mock the Enum. enum example in src/types.d
|
Issue :
Const enum still not working
As stated on the documentation: https://kulshekhar.github.io/ts-jest/user/babel7-or-ts#no-const-enum,
there is still some problems with const enum in TS. In issue #281 there was a reference to PR #505 as a possible solution and #697 as a release that featured those changes.
I tried setting the useExperimentalLanguageServer flag to true in globals, and though it seems to not fail in the enums, it has problems resolving imported modules, both in relative and in aliased paths, throwing:
TSC language server encountered errors while transpiling. Errors: Cannot find module
If I set the flag to false, it just fails on const enums, which of course I can work around with the suggested
let Enum: Enum = 1 as Enum
or similar approaches and everything works fine, but I was really hoping to give full support to the code without working around them.So, my main question or reason for reporting this, is that I am not sure of how the TSC language server works and why is it messing with module resolution when turned on.
My settings:
jest.conf.js
tsconfig.json
babelrc
And just in case, error with routes using aliases:
TSC language server encountered errors while transpiling. Errors: Cannot find module '@/components/player/player.vue'.
Without aliases:
TSC language server encountered errors while transpiling. Errors: Cannot find module './player/player.vue'.
Everything working with the flag set to false and work around for const enum:
Expected behavior :
As stated in the title and description, I am pretty sure this is not an issue, since the repo specifically says this is a TS issue that they are not willing to fix/address, but just to be sure, I wanted to see if there was anything else at play.
You can contact me in the ts-jest slack, I sent this same inquire in the general channel (Pedro/Peter is my handle and show name).
Thanks for your time. Have a great day.
Debug log:
log file content
# content of ts-jest.log :
Minimal repo :
The text was updated successfully, but these errors were encountered: