Skip to content
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

Assertion signature not working on private identifier #42166

Closed
ajafff opened this issue Dec 31, 2020 · 0 comments · Fixed by #42176
Closed

Assertion signature not working on private identifier #42166

ajafff opened this issue Dec 31, 2020 · 0 comments · Fixed by #42176
Labels
Bug A bug in TypeScript
Milestone

Comments

@ajafff
Copy link
Contributor

ajafff commented Dec 31, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants