microsoft / microsoft/TypeScript
Proposal: Allow isolated declarations to infer results of constructor calls
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔍 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
^
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
L'issue non indica file, test o punti di ingresso; inizia tracciando i controlli esistenti di --isolatedDeclarations e il comportamento di inferenza delle dichiarazioni. Il lavoro è completo quando i risultati delle chiamate ai costruttori possono essere inferiti con l'impostazione proposta e il controllo dei tipi rifiuta i tipi inferiti o annotati non corrispondenti senza modificare il JavaScript emesso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100