microsoft / microsoft/TypeScript
Allowing subsequent property declarations of compatible types
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Search Terms
TS2717, subsequent property declarations
Suggestion
Let's assume following code:
Library typings:
interface Dictionary<T> {
[key: string]: T;
}
interface Foo {
methods: Dictionary<Function>;
}
User extension:
declare module "@awesome/library" {
interface BagOfFunctions extends Dictionary<Function> {
wellKnownFunction(foo: number): number;
}
interface Foo {
methods: BagOfFunctions;
}
}
Currently, it results in TS2717. After this change, such code will be allowed.
Use Cases
Use case: Hapi allow user to define global functions with shared cache (server.method).
Unfortunely, server.methods is currently defined as Dictionary<ServerMethod> and end users aren't able to get type safety when calling them.
Checklist
My suggestion meets these guidelines:
- 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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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 la diagnostica TS2717 e il comportamento di merging delle dichiarazioni mostrato negli esempi. Confronta il rifiuto attuale di Foo.methods con l’accettazione richiesta di BagOfFunctions, quindi definisci la copertura per le redeclarazioni compatibili e incompatibili. Il lavoro è completato quando l’estensione di esempio viene accettata senza indebolire gli errori relativi alle proprietà incompatibili.
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
- 35/100