microsoft / microsoft/TypeScript
Class with private 'then' method can be awaited outside of the class
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il repro TypeScript fornito e il link a Playground, confrontando il comportamento di await new C() dentro e fuori dalla classe. Esamina la issue correlata #42190 per il contesto; il lavoro è completato quando l’await esterno segnala che il metodo then privato di C è incompatibile con PromiseLike.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100