microsoft / microsoft/TypeScript
Proposal: Allow isolated declarations to infer results of constructor calls
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔍 Search Terms
isolated declarations constructor generic infer
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Add a new flag or change the behavior of --isolatedDeclarations so that in the following code which is currently disallowed by isolated declarations:
export const foo = new Foo(a);
if the type of foo is not Foo, there is a typecheck error. In return, the type of foo will be emitted as Foo.
Similarly, if somehow in
export const foo: new Foo<A>(a);
foo is not a Foo<A>, there is a typecheck error.
📃 Motivating Example
Currently under isolated declarations, code must redundantly declare the type of a variable which is the result of a constructor call.
export const foo: Foo = new Foo(a);
This setting would also eliminate https://github.com/microsoft/TypeScript/issues/59768
💻 Use Cases
^
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
Das Issue nennt keine Dateien, Tests oder Einstiegspunkte; beginne damit, die bestehenden Prüfungen für --isolatedDeclarations und das Verhalten bei der Inferenz von Deklarationen nachzuverfolgen. Als erledigt gilt die Aufgabe, wenn Ergebnisse von Konstruktoraufrufen unter der vorgeschlagenen Einstellung inferiert werden können und die Typprüfung nicht übereinstimmende inferierte oder annotierte Typen zurückweist, ohne das erzeugte JavaScript zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100