-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Jquery error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided. #20703
Comments
@mhegazy I was discussing this with Skype earlier this week - it would be much better if |
If it is consumed by a ts file, how to use JQuery types with |
I have created a dtslint issue to ban |
We need to expand the lint rule on DefinitelyTyped as Separately, accepting PRs to move the error from a |
@RyanCavanaugh const app = new ActiveXObject('Access.Application');
app.RunCommand(97); // what is 97? the enum values could be defined in the declare namespace Access {
const enum AcCommand {
// ...
acCmdSaveRecord = 97,
// ...
}
} and consumed by the app.RunCommand(Access.AcCommand.acCmdSaveRecord); and inlined on compilation. Ideally, these values should be part of the object model: // Javascript implementation code
var Access = {
AcCommand: {
acCmdSaveRecord: 97
}
}; and could then be referred to in the Perhaps this isn't the best mechanism for inlining declared values, as app.RunCommand(-42); even though |
You should use a union type of literals (string or number) instead. I understand the documentation rational. but a declaration file is included in multiple projects, and the author of the declaration can not control how the user will build their project. And thus, a .d.ts should adhere to the least common denominator of compiler options. this is not any different from |
Understood. My question is now, why does |
The flag is meant to support transpiling a single file at a time. i.e. the whole project is not loaded when a file is transformed. and thus the compiler does not have access ot the .d.ts file to find out what values to use. |
@mhegazy I must be missing something here -- so how can anything from the |
Consider for example using babel to transpile a TS project. you would run tsc as a type checker only, but not as a transpiler. babel only transpiles one file at a time, and has no way to get access to the .d.ts. hope this explains it. |
@mhegazy Yes, thanks. |
I have the same error with |
Same problem with |
Is replacing const emuns by string union types in DefinitelyTyped repo the only way to fix this error? |
@chicoxyzzy Did you find out what's the best practice to handle this problem? |
@chicoxyzzy @noelyoo You can disable the |
Disabling the 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 |
@noelyoo my workaround has been to remove I think the best long-term solution is #20703 (comment) (making |
@alangpierce @chicoxyzzy I solved the above issue by setting |
…ccess Fixes microsoft#20703 with solution suggested in microsoft#20703 (comment) Previously, `--isolatedModules` gave an error for any ambient const enum, which meant that some third-party libraries would always give errors even if the ambient const enums they declare were never used. Now, we only give an error when an ambient const enum is referenced, which allows such libraries to still be used as long as the const enums are never accessed. Some nuances: * As before, the error is only surfaced for *ambient* const enums. With non-ambient const enums, we know that an `isolatedModules` build will emit the enum and produce a plain reference rather than inlining the constant, so everything will still work. * I originally planned to do this check in the code path that inlines the constant, but that code is only exercised at emit time, so, for example, the TS language service wasn't giving an error in my editor. Instead, I do the check at typecheck time next to another const-enum-related check. * This can be a breaking change when using `skipLibCheck` because the error is typically moved from a .d.ts file to a .ts file. Testing done: I ran this TS build on a large project of mine that previously had disabled `isolatedModules` so I could use the `chalk` library. With `isolatedModules` enabled, there was no longer an error in the chalk typedefs, and a reference to the `Level` const enum produced an error in my editor.
I put up a PR to change the error to happen when accessing an ambient const enum rather than declaring one (#20703 (comment)), which should pretty much make this a non-issue: #28465. |
Hoping it will be available in the next 1.3.7 distributive. This error is showstopper for us. |
I was able to resolve this myself by applying the change I made in this PR with patch-package to override the official |
TypeScript Version: 2.6.2
Code
Executing
tsc -p .
.Expected behavior:
successfully compiled /build/dist/{tsfilename}.js for each ts module:
Actual behavior:
The text was updated successfully, but these errors were encountered: