1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
tests/cases/compiler/mappedTypeIndexedAccess.ts(18,5): error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type 'Pair<FooBar>'.
Types of property 'value' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/mappedTypeIndexedAccess.ts(24,5): error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; } | { key: "bar"; value: number; }'.
Types of property 'value' are incompatible.
Type 'number' is not assignable to type 'string'.
==== tests/cases/compiler/mappedTypeIndexedAccess.ts (2 errors) ====
// Repro from #15756
type Pairs<T> = {
[TKey in keyof T]: {
key: TKey;
value: T[TKey];
};
};
type Pair<T> = Pairs<T>[keyof T];
type FooBar = {
foo: string;
bar: number;
};
// Error expected here
let pair1: Pair<FooBar> = {
~~~~~
!!! error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type 'Pair<FooBar>'.
!!! error TS2322: Types of property 'value' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
key: "foo",
value: 3
};
// Error expected here
let pair2: Pairs<FooBar>[keyof FooBar] = {
~~~~~
!!! error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; } | { key: "bar"; value: number; }'.
!!! error TS2322: Types of property 'value' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
key: "foo",
value: 3
};
|