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
[isolatedDeclarations][5.5] Disagreement between transpileDeclaration API and typechecker on Symbol.iterator as computed property #58490
Comments
@dragomirtitian @weswigham here's a fun one for y'all π |
For computed properties we allow them to be used in isolated declarations even if we can't determine the type is valid locally. This was due to the fact that computed properties with unique symbols would otherwise be completely unusable with isolated declarations. In |
It is. The issue is that the check for the ID error (in Symbols are a big hole in const sym = Symbol();
export class Foo {
public [sym]() {
return {
next: () => ({ value: 42, done: false }),
};
}
} I've currently patched into emitting "correctly", but still issuing the |
Would you happen to know of a clean and concise way to annotate code following this pattern to satisfy isolatedDeclarations? IIRC they can't be suppressed by |
The issue with the symbol computed names is that there isn't one - to write it you'd still need a type with a symbol computed name, which then has the same issue. Call it a flaw with the whole idea that you can do declaration emit without expression checking, since computed names mean even types can rely on (nonlocal!) expression evaluation - minimally you need to make breaking assumptions that expressions in computed names probably resolve to valid property names that probably don't conflict with other property names. Or you give up and do some limited checking-like analysis - looking for references to the global |
Hm. Wonder if it would be too special casey to look for expressions that match the pattern |
To be even more explicit, this // @filename: defines.d.ts
export const mySymbol: unique symbol;
// @filename: usage.ts
import {mySymbol} from "./defines.js"
export class Foo {
[mySymbol]() {}
} is something you want to allow because it's how symbols are meant to be used, but // @filename: defines.d.ts
export const mySymbol: string;
// @filename: usage.ts
import {mySymbol} from "./defines.js"
export class Foo {
[mySymbol]() {}
} is something you need to forbid because you don't know if |
π Search Terms
isolated declarations transpileDeclaration symbol iterator
π Version & Regression Information
β― Playground Link
https://tsplay.dev/wXLvLw
π» Code
π Actual behavior
ts.transpileDeclaration
has diagnostic:Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations.
tsc --isolatedDeclarations
completes successfullyπ Expected behavior
I'm not sure which is more correct here. If we treat this as not an error, then that seems to imply that
Symbol.iterator
is treated specially, which runs into weird edge cases likeSymbol
being overridden in the current scope. But if we do treat this as an error, then the question becomes how does one add an explicit type annotation for this case?Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: