microsoft / microsoft/TypeScript
Interface merging for any property names does not allow type narrowing
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
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
Beginne mit der verlinkten TypeScript Playground-Reproduktion und bestätige die Diagnose für die beiden zusammengeführten PropsContainer-Deklarationen. Verfolge anschließend den Type-Checking-Pfad für nachfolgende Eigenschaftsdeklarationen und Indexsignaturen. Fertig ist es, wenn der gezeigte Merge akzeptiert wird, specialProp auf string eingeengt wird und bestehende inkompatible Neudeklarationen weiterhin abgelehnt werden.
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
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100