microsoft / microsoft/TypeScript
Common property check isn't performed when the target has any index signature
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 Search Terms
common property check weak type index signature
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type Delay<TDelay extends string> = TDelay | number;
interface MachineConfig<TDelay extends string> {
types?: unknown;
after?: {
[K in Delay<TDelay>]?: number;
};
}
declare function test<
TDelay extends string,
TConfig extends MachineConfig<TDelay>,
>(config: { types: { delays: TDelay } } & TConfig): void;
test({
types: {} as {
delays: "one second" | "one minute";
},
after: {
// @ts-expect-error
oops_this_is_unknown_delay: 100,
},
});
function test2<T extends { [x: `id-${number}`]: string }>(a: T) {}
test2({
// @ts-expect-error
random: true,
});
function test3<T extends { [x: symbol]: string }>(a: T) {}
test3({
// @ts-expect-error
random: true,
});
🙁 Actual behavior
No errors are raised here since index signatures turn off the common property check completely.
🙂 Expected behavior
I don't have a good intuition about the common property check so I'm not sure if all of those 3 examples should be treated as bugs/possible improvements. I think though that especially the first one is surprising because I have a list of 2 concrete string properties that are meant to be allowed there and yet the unrelated~ index signature for numbers turns off this check, leading to accidental problems at runtime.
Additional information about the issue
No response
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 dem verlinkten TypeScript Playground und vergleiche die drei Beispiele in test, test2 und test3. Verfolge, wie die Prüfung gemeinsamer Eigenschaften mit gemappten, Template-Literal- und Symbol-Indexsignaturen funktioniert; als abgeschlossen gilt die Aufgabe, wenn die beabsichtigten Diagnosen und die erwartete Behandlung aller drei Fälle feststehen.
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
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100