microsoft / microsoft/TypeScript
Class with private 'then' method can be awaited outside of the class
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit dem bereitgestellten TypeScript-Repro und dem Playground-Link und vergleichen Sie, wie sich das Awaiting von new C() innerhalb und außerhalb der Klasse verhält. Untersuchen Sie das zugehörige Issue #42190 als Kontext; abgeschlossen ist die Aufgabe, wenn das Awaiting außerhalb der Klasse meldet, dass die private then-Methode von C nicht mit PromiseLike kompatibel ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100