-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Certain resolution-dependent enum emit isn't correctly flagged as an error under isolatedModules
#56153
Comments
Just to be clear, |
import { Foo } from "./foo";
export var Bar;
(function(Bar) {
Bar[Bar["B"] = Foo.A] = "B";
Bar[Bar["C"] = Foo.A + 1] = "C";
})(Bar || (Bar = {})); So the bug here is either that:
I'm leaning toward the first option for the sake of compat and convenience. |
I don't believe // @filename: foo.ts
export enum Foo{
A = "10"
}
// @filename: index.ts
import { Foo } from "./foo";
export enum Bar {
B = Foo.A,
C
} In the above example, tsc will return // @filename: foo.ts
export var Foo = {
A: 10
};
// @filename: index.ts
import { Foo } from "./foo";
export enum Bar {
B = Foo.A,
C
} In this example, |
|
You are right. However, as far as I know, there are still people who try to use One possible input: // @filename: foo.ts
export enum Foo {
A = 10,
}
(Foo.A as any) = "10"
// @filename: index.ts
import { Foo } from "./foo";
export enum Bar {
B = Foo.A,
C
} |
Maybe same issue in |
I would think that the moment you're doing something unsafe like casting an enum or |
@RyanCavanaugh Sorry to bother you again. // @showEmit
// @isolatedModules: true
// @filename: foo.ts
export enum Foo {
"Infinity" = 1,
A = 1 / 0,
}
// @filename: index.ts
import { Foo } from "./foo";
export enum Bar {
B = Foo.Infinity,
C
} The tsc says that the |
That's a separate bug -- TSC should probably disallow |
I am trying to fix this. But I found that |
It was accepted as a bug at #48956. |
TL;DR from #56164. Under
|
isolatedModules: true
still link enum cross moduleisolatedModules
(from the meeting notes)
Note that Babel currently transforms enum Bar {
B = Foo.A,
C
} to var Bar = function (Bar) {
Bar[Bar["B"] = Foo.A] = "B";
Bar[Bar["C"] = 1 + Bar["B"]] = "C";
return Bar;
}(Bar || {}); Is this what was meant by "work"? Or is this correct only under the new proposed behavior? |
Yes, though under the agreed-on rules, |
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in the issue body running against the nightly TypeScript. Issue body code block by @magic-akari 👍 Compiled import { Foo } from "./foo";
export var Bar;
(function (Bar) {
Bar[Bar["B"] = 10] = "B";
Bar[Bar["C"] = 11] = "C";
})(Bar || (Bar = {})); Historical Information
|
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of this repro running against the nightly TypeScript. 👍 Compiled import { Foo } from "./foo";
export var Bar;
(function (Bar) {
Bar[Bar["B"] = 1] = "B";
Bar[Bar["C"] = 2] = "C";
})(Bar || (Bar = {})); Historical Information
|
Could we allow template expressions? E.g. the following is guaranteed to have a string value. How do you feel about allowing that and not generating a reverse mapping for it? enum Foo { A = `${Bar.A}` } Edit: Never mind. Turns out in our code base this pattern happens so rarely, this doesn't feel worth the effort. |
🔎 Search Terms
🕗 Version & Regression Information
Test on Playground with version 3.9.7 and version 5.2.2, got the same incorrect result.
⏯ Playground Link
Workbench Repro
💻 Code
Workbench Repro
🙁 Actual behavior
Please notice the value of Bar.C
🙂 Expected behavior
Emit a warning or an error, and generate code that does not rely on other imports.
Example:
The Bar.C is void 0, since it cannot be refered.
Additional information about the issue
The text was updated successfully, but these errors were encountered: