Microsoft/TypeScript
GitHub ã§èŠãUnable to use Symbol as key for jsdoc `@typedef`
Open
#47,259 opened on 2021幎12æ28æ¥
BugDomain: JSDocHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
Bug Report
ð Search Terms
jsdoc ts2454
ð Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
2454
⯠Playground Link
Playground link with relevant code
ð» Code
class Foo {
someProp = "value";
}
const sym = Symbol("sym");
/** @typedef {Foo & { [sym]?: string }} FooWithSym */
// ^^^----- Variable 'sym' is used before being assigned (2454)
Note that this error only happens with strictNullChecks enabled.
ð Actual behavior
ts2454
ð Expected behavior
No errors
When using TypeScript rather than JavaScript, this error does not occur.
Here is the TypeScript equivalent: (playground)
// Normally this would be an imported class
class Foo {
someProp = "value";
}
// add the symbol type to Foo
const sym = Symbol("sym");
type FooWithSym = Foo & {
[sym]?: string;
}
const withoutSym = new Foo();
withoutSym[sym] = "test"; // error, as expected
const withSym : FooWithSym = new Foo();
withSym[sym] = "test"; // this works
const y = withSym[sym];
console.log(y); // y is `string | undefined`