microsoft / microsoft/TypeScript
Interface merging for any property names does not allow type narrowing
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: 4.1.0-dev.20201002
Search Terms: interface merging merge object any name subsequent property declarations
Code
interface PropsContainer {
props: {
[propName: string]: any;
}
}
interface PropsContainer {
props: {
[propName: string]: any;
specialProp: string;
}
}
Expected behavior:
This should be allowed. The merged interface should result in a type with props that have any prop name as any except for specialProp which is a string.
This would be useful in a case where a third party library (such as @types/react-test-renderer) declare an object type with { [propName: string]: any } syntax, but you want to narrow the value of the property for specific types via interface merging.
Note that even { specialProp?: any, [propName: string]: any } is not allowed even though the types are functionally identical in this case.
Actual behavior:
This results in a Subsequent property declarations must have the same type.
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 riproduzione collegata in TypeScript Playground e conferma la diagnosi per le due dichiarazioni PropsContainer unite. Poi traccia il percorso del controllo dei tipi per le dichiarazioni di proprietà e le firme di indice successive. Il lavoro è completato quando l’unione mostrata viene accettata, specialProp viene ristretto a string e le redeclarazioni incompatibili esistenti continuano a essere rifiutate.
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
- Specificata chiaramente
- Idoneità per principianti
- 35/100