-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
TypeScript Version: 4.2.0-dev.20201231
Search Terms: private assert
Expected behavior:
Both methods work the same, no compile error.
Actual behavior:
Error on this.#assert
: Assertions require every name in the call target to be declared with an explicit type annotation.(2775)
AFAICT this is caused by getTypeOfDottedName
using getPropertyOfType
with property name #assert
, which doesn't work for private identifiers. Instead is looks for a regular property with name '#assert'
. If I add '#assert': (v: any) => asserts v = (v) => {};
the error goes away.
Code
class C {
assert: (v: any) => asserts v = (v) => {};
#assert: (v: any) => asserts v = (v) => {};
works(v: boolean) {
this.assert(v);
v;
}
doesntWork(v: boolean) {
this.#assert(v);
v;
}
}
Playground Link: Provided
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript