TypeScript: Jquery error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided.
TypeScript Version: 2.6.2
Code
//package.json:
{
"name": "issue-ts-isolatedmodule",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^3.2.1"
}
,"devDependencies": {
"typescript": "^2.6.2",
"@types/jquery":"^3.2.17"
}
}
//tsconfig.json
{
"compilerOptions": {
"outDir": "build/dist",
"module": "esnext",
"target": "es5",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"suppressImplicitAnyIndexErrors": true,
"isolatedModules": true,
"preserveConstEnums": true,
"preserveSymlinks": true,
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules",
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts"
]
}
//src/index.ts
export function HalloWorld(){
return "Hallo world!"
}
Executing tsc -p ..
Expected behavior: successfully compiled /build/dist/{tsfilename}.js for each ts module:
Actual behavior:
node_modules/@types/jquery/index.d.ts(7690,16): error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided.
node_modules/@types/jquery/index.d.ts(7698,16): error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (15 by maintainers)
Commits related to this issue
- Change isolatedModules to allow const enum declaration and disallow access Fixes #20703 with solution suggested in https://github.com/Microsoft/TypeScript/issues/20703#issuecomment-361434795 Previou... — committed to alangpierce/TypeScript by alangpierce 6 years ago
- fix: support `--isolatedModules` https://github.com/microsoft/TypeScript/issues/20703 — committed to ember-intl/ember-intl by buschtoens 4 years ago
- fix: support `--isolatedModules` (#1423) https://github.com/microsoft/TypeScript/issues/20703 — committed to ember-intl/ember-intl by buschtoens 4 years ago
I have the same error with
chalkand@types/range-parserin node_modules. I cannot change them, and use babel with@babel/preset-typescript, any plans on fixing this ? How can I help ?@alangpierce @chicoxyzzy I solved the above issue by setting
skipLibCheckastrueintsconfig.jsonbased on ianschmitz’s suggestion.https://github.com/facebook/create-react-app/issues/5738
We need to expand the lint rule on DefinitelyTyped as
const enumon DT really does not make sense.Separately, accepting PRs to move the error from a
const enumexisting to a const enum being referenced (in a value position) whenisolatedModulesis on. Should be relatively easy.I put up a PR to change the error to happen when accessing an ambient const enum rather than declaring one (https://github.com/Microsoft/TypeScript/issues/20703#issuecomment-361434795), which should pretty much make this a non-issue: #28465.
@zspitz
Disabling the
no-const-enumrule does not solve this problem:Failed to compile.
/Users/noel/react-auth-demo/node_modules/monaco-editor/esm/vs/editor/editor.api.d.ts h-demo/src/containType error: Ambient const enums are not allowed when the ‘–isolatedModules’ flag is provided. TS1209
I have created a dtslint issue to ban
const enumsin declaration files. i think a declaration file in general should be applicable to the strictest settings, and this includes--isolatedModules.I was able to resolve this myself by applying the change I made in this PR with patch-package to override the official
@types/package. This approach can be used to work around the issue for other libraries with outdated types too.