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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
=== tests/cases/conformance/types/mapped/mappedTypeWithAny.ts ===
type Item = { value: string };
>Item : { value: string; }
>value : string
type ItemMap<T> = { [P in keyof T]: Item };
>ItemMap : ItemMap<T>
declare let x0: keyof any;
>x0 : string | number | symbol
declare let x1: { [P in any]: Item };
>x1 : { [x: string]: Item; [x: number]: Item; [x: symbol]: Item; }
declare let x2: { [P in string]: Item };
>x2 : { [x: string]: Item; }
declare let x3: { [P in keyof any]: Item };
>x3 : { [x: string]: Item; }
declare let x4: ItemMap<any>;
>x4 : ItemMap<any>
// Repro from #19152
type Data = {
>Data : { value: string; }
value: string;
>value : string
}
type StrictDataMap<T> = {
>StrictDataMap : StrictDataMap<T>
[P in keyof T]: Data
}
declare let z: StrictDataMap<any>;
>z : StrictDataMap<any>
for (let id in z) {
>id : string
>z : StrictDataMap<any>
let data = z[id];
>data : Data
>z[id] : Data
>z : StrictDataMap<any>
>id : string
let x = data.notAValue; // Error
>x : any
>data.notAValue : any
>data : Data
>notAValue : any
}
// Issue #46169.
// We want mapped types whose constraint is `keyof T` to
// map over `any` differently, depending on whether `T`
// is constrained to array and tuple types.
type Arrayish<T extends unknown[]> = { [K in keyof T]: T[K] };
>Arrayish : Arrayish<T>
type Objectish<T extends unknown> = { [K in keyof T]: T[K] };
>Objectish : Objectish<T>
// When a mapped type whose constraint is `keyof T` is instantiated,
// `T` may be instantiated with a `U` which is constrained to
// array and tuple types. *Ideally*, when `U` is later instantiated with `any`,
// the result should also be some sort of array; however, at the moment we don't seem
// to have an easy way to preserve that information. More than just that, it would be
// inconsistent for two instantiations of `Objectish<any>` to produce different outputs
// depending on the usage-site. As a result, `IndirectArrayish` does not act like `Arrayish`.
type IndirectArrayish<U extends unknown[]> = Objectish<U>;
>IndirectArrayish : Objectish<U>
function bar(arrayish: Arrayish<any>, objectish: Objectish<any>, indirectArrayish: IndirectArrayish<any>) {
>bar : (arrayish: Arrayish<any>, objectish: Objectish<any>, indirectArrayish: IndirectArrayish<any>) => void
>arrayish : any[]
>objectish : Objectish<any>
>indirectArrayish : Objectish<any>
let arr: any[];
>arr : any[]
arr = arrayish;
>arr = arrayish : any[]
>arr : any[]
>arrayish : any[]
arr = objectish;
>arr = objectish : Objectish<any>
>arr : any[]
>objectish : Objectish<any>
arr = indirectArrayish;
>arr = indirectArrayish : Objectish<any>
>arr : any[]
>indirectArrayish : Objectish<any>
}
declare function stringifyArray<T extends readonly any[]>(arr: T): { -readonly [K in keyof T]: string };
>stringifyArray : <T extends readonly any[]>(arr: T) => { -readonly [K in keyof T]: string; }
>arr : T
let abc: any[] = stringifyArray(void 0 as any);
>abc : any[]
>stringifyArray(void 0 as any) : string[]
>stringifyArray : <T extends readonly any[]>(arr: T) => { -readonly [K in keyof T]: string; }
>void 0 as any : any
>void 0 : undefined
>0 : 0
declare function stringifyPair<T extends readonly [any, any]>(arr: T): { -readonly [K in keyof T]: string };
>stringifyPair : <T extends readonly [any, any]>(arr: T) => { -readonly [K in keyof T]: string; }
>arr : T
let def: [any, any] = stringifyPair(void 0 as any);
>def : [any, any]
>stringifyPair(void 0 as any) : string[]
>stringifyPair : <T extends readonly [any, any]>(arr: T) => { -readonly [K in keyof T]: string; }
>void 0 as any : any
>void 0 : undefined
>0 : 0
// Repro from #46582
type Evolvable<E extends Evolver> = {
>Evolvable : Evolvable<E>
[P in keyof E]: never;
};
type Evolver<T extends Evolvable<any> = any> = {
>Evolver : Evolver<T>
[key in keyof Partial<T>]: never;
};
|