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
|
=== tests/cases/compiler/inferFromNestedSameShapeTuple.ts ===
// repro #48524
type Magic<X> = X extends [[infer Y, ...infer _], ...infer __] ? Y : never;
>Magic : Magic<X>
type R = Magic<[[number]]>
>R : number
// repro #52722
type Recursive<Id> = {
>Recursive : Recursive<Id>
id: Id
>id : Id
children: readonly Recursive<Id>[]
>children : readonly Recursive<Id>[]
}
declare function getIds<Id>(items: readonly Recursive<Id>[]): Id[];
>getIds : <Id>(items: readonly Recursive<Id>[]) => Id[]
>items : readonly Recursive<Id>[]
const items = [{
>items : readonly [{ readonly id: "a"; readonly children: readonly [{ readonly id: "b"; readonly children: readonly []; }]; }]
>[{ id: 'a', children: [{ id: 'b', children: [] }]}] as const satisfies readonly Recursive<string>[] : readonly [{ readonly id: "a"; readonly children: readonly [{ readonly id: "b"; readonly children: readonly []; }]; }]
>[{ id: 'a', children: [{ id: 'b', children: [] }]}] as const : readonly [{ readonly id: "a"; readonly children: readonly [{ readonly id: "b"; readonly children: readonly []; }]; }]
>[{ id: 'a', children: [{ id: 'b', children: [] }]}] : readonly [{ readonly id: "a"; readonly children: readonly [{ readonly id: "b"; readonly children: readonly []; }]; }]
>{ id: 'a', children: [{ id: 'b', children: [] }]} : { readonly id: "a"; readonly children: readonly [{ readonly id: "b"; readonly children: readonly []; }]; }
id: 'a',
>id : "a"
>'a' : "a"
children: [{
>children : readonly [{ readonly id: "b"; readonly children: readonly []; }]
>[{ id: 'b', children: [] }] : readonly [{ readonly id: "b"; readonly children: readonly []; }]
>{ id: 'b', children: [] } : { readonly id: "b"; readonly children: readonly []; }
id: 'b',
>id : "b"
>'b' : "b"
children: []
>children : readonly []
>[] : readonly []
}]
}] as const satisfies readonly Recursive<string>[]
const foo = getIds(items)
>foo : ("a" | "b")[]
>getIds(items) : ("a" | "b")[]
>getIds : <Id>(items: readonly Recursive<Id>[]) => Id[]
>items : readonly [{ readonly id: "a"; readonly children: readonly [{ readonly id: "b"; readonly children: readonly []; }]; }]
// variant with a fresh argument
const foo2 = getIds([{
>foo2 : ("a" | "b")[]
>getIds([{ id: 'a', children: [{ id: 'b', children: [] }]}] as const) : ("a" | "b")[]
>getIds : <Id>(items: readonly Recursive<Id>[]) => Id[]
>[{ id: 'a', children: [{ id: 'b', children: [] }]}] as const : readonly [{ readonly id: "a"; readonly children: readonly [{ readonly id: "b"; readonly children: readonly []; }]; }]
>[{ id: 'a', children: [{ id: 'b', children: [] }]}] : readonly [{ readonly id: "a"; readonly children: readonly [{ readonly id: "b"; readonly children: readonly []; }]; }]
>{ id: 'a', children: [{ id: 'b', children: [] }]} : { readonly id: "a"; readonly children: readonly [{ readonly id: "b"; readonly children: readonly []; }]; }
id: 'a',
>id : "a"
>'a' : "a"
children: [{
>children : readonly [{ readonly id: "b"; readonly children: readonly []; }]
>[{ id: 'b', children: [] }] : readonly [{ readonly id: "b"; readonly children: readonly []; }]
>{ id: 'b', children: [] } : { readonly id: "b"; readonly children: readonly []; }
id: 'b',
>id : "b"
>'b' : "b"
children: []
>children : readonly []
>[] : readonly []
}]
}] as const)
// Repro from comment in #49226
type T1<T> = [number, T1<{ x: T }>];
>T1 : T1<T>
>x : T
type T2<T> = [42, T2<{ x: T }>];
>T2 : T2<T>
>x : T
function qq<U>(x: T1<U>, y: T2<U>) {
>qq : <U>(x: T1<U>, y: T2<U>) => void
>x : T1<U>
>y : T2<U>
x = y;
>x = y : T2<U>
>x : T1<U>
>y : T2<U>
y = x; // Error
>y = x : T1<U>
>y : T2<U>
>x : T1<U>
}
|