microsoft / microsoft/TypeScript
Class with private 'then' method can be awaited outside of the class
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 4.2.0-dev.20210103, goes all the way back to 3.3.3333 and probably further
Search Terms: await private then
Expected behavior:
Expected error when awaiting C outside of the class body:
Type 'C' is not assignable to type 'PromiseLike'.
Property 'then' is private in type 'C' but not in type 'PromiseLike'.
Actual behavior:
Instance of C can be awaited inside and outside of the class body without an error.
Related Issues: #42190
Code
class C {
private then<T>(cb: (v: string) => PromiseLike<T> | T): Promise<T> {
return null!;
}
}
(async () => await new C())();
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided TypeScript repro and Playground link, comparing how awaiting new C() behaves inside and outside the class. Investigate the related issue #42190 for context; done means the outside await reports that C's private then method is incompatible with PromiseLike.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100