|
| 1 | +=== tests/cases/conformance/types/keyof/keyofIntersection.ts === |
| 2 | +type A = { a: string }; |
| 3 | +>A : Symbol(A, Decl(keyofIntersection.ts, 0, 0)) |
| 4 | +>a : Symbol(a, Decl(keyofIntersection.ts, 0, 10)) |
| 5 | + |
| 6 | +type B = { b: string }; |
| 7 | +>B : Symbol(B, Decl(keyofIntersection.ts, 0, 23)) |
| 8 | +>b : Symbol(b, Decl(keyofIntersection.ts, 1, 10)) |
| 9 | + |
| 10 | +type T01 = keyof (A & B); // "a" | "b" |
| 11 | +>T01 : Symbol(T01, Decl(keyofIntersection.ts, 1, 23)) |
| 12 | +>A : Symbol(A, Decl(keyofIntersection.ts, 0, 0)) |
| 13 | +>B : Symbol(B, Decl(keyofIntersection.ts, 0, 23)) |
| 14 | + |
| 15 | +type T02<T> = keyof (T & B); // "b" | keyof T |
| 16 | +>T02 : Symbol(T02, Decl(keyofIntersection.ts, 3, 25)) |
| 17 | +>T : Symbol(T, Decl(keyofIntersection.ts, 4, 9)) |
| 18 | +>T : Symbol(T, Decl(keyofIntersection.ts, 4, 9)) |
| 19 | +>B : Symbol(B, Decl(keyofIntersection.ts, 0, 23)) |
| 20 | + |
| 21 | +type T03<U> = keyof (A & U); // "a" | keyof U |
| 22 | +>T03 : Symbol(T03, Decl(keyofIntersection.ts, 4, 28)) |
| 23 | +>U : Symbol(U, Decl(keyofIntersection.ts, 5, 9)) |
| 24 | +>A : Symbol(A, Decl(keyofIntersection.ts, 0, 0)) |
| 25 | +>U : Symbol(U, Decl(keyofIntersection.ts, 5, 9)) |
| 26 | + |
| 27 | +type T04<T, U> = keyof (T & U); // keyof T | keyof U |
| 28 | +>T04 : Symbol(T04, Decl(keyofIntersection.ts, 5, 28)) |
| 29 | +>T : Symbol(T, Decl(keyofIntersection.ts, 6, 9)) |
| 30 | +>U : Symbol(U, Decl(keyofIntersection.ts, 6, 11)) |
| 31 | +>T : Symbol(T, Decl(keyofIntersection.ts, 6, 9)) |
| 32 | +>U : Symbol(U, Decl(keyofIntersection.ts, 6, 11)) |
| 33 | + |
| 34 | +type T05 = T02<A>; // "a" | "b" |
| 35 | +>T05 : Symbol(T05, Decl(keyofIntersection.ts, 6, 31)) |
| 36 | +>T02 : Symbol(T02, Decl(keyofIntersection.ts, 3, 25)) |
| 37 | +>A : Symbol(A, Decl(keyofIntersection.ts, 0, 0)) |
| 38 | + |
| 39 | +type T06 = T03<B>; // "a" | "b" |
| 40 | +>T06 : Symbol(T06, Decl(keyofIntersection.ts, 7, 18)) |
| 41 | +>T03 : Symbol(T03, Decl(keyofIntersection.ts, 4, 28)) |
| 42 | +>B : Symbol(B, Decl(keyofIntersection.ts, 0, 23)) |
| 43 | + |
| 44 | +type T07 = T04<A, B>; // "a" | "b" |
| 45 | +>T07 : Symbol(T07, Decl(keyofIntersection.ts, 8, 18)) |
| 46 | +>T04 : Symbol(T04, Decl(keyofIntersection.ts, 5, 28)) |
| 47 | +>A : Symbol(A, Decl(keyofIntersection.ts, 0, 0)) |
| 48 | +>B : Symbol(B, Decl(keyofIntersection.ts, 0, 23)) |
| 49 | + |
| 50 | +// Repros from #22291 |
| 51 | + |
| 52 | +type Example1<T extends string, U extends string> = keyof (Record<T, any> & Record<U, any>); |
| 53 | +>Example1 : Symbol(Example1, Decl(keyofIntersection.ts, 9, 21)) |
| 54 | +>T : Symbol(T, Decl(keyofIntersection.ts, 13, 14)) |
| 55 | +>U : Symbol(U, Decl(keyofIntersection.ts, 13, 31)) |
| 56 | +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) |
| 57 | +>T : Symbol(T, Decl(keyofIntersection.ts, 13, 14)) |
| 58 | +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) |
| 59 | +>U : Symbol(U, Decl(keyofIntersection.ts, 13, 31)) |
| 60 | + |
| 61 | +type Result1 = Example1<'x', 'y'>; // "x" | "y" |
| 62 | +>Result1 : Symbol(Result1, Decl(keyofIntersection.ts, 13, 92)) |
| 63 | +>Example1 : Symbol(Example1, Decl(keyofIntersection.ts, 9, 21)) |
| 64 | + |
| 65 | +type Result2 = keyof (Record<'x', any> & Record<'y', any>); // "x" | "y" |
| 66 | +>Result2 : Symbol(Result2, Decl(keyofIntersection.ts, 14, 34)) |
| 67 | +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) |
| 68 | +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) |
| 69 | + |
| 70 | +type Example3<T extends string> = keyof (Record<T, any>); |
| 71 | +>Example3 : Symbol(Example3, Decl(keyofIntersection.ts, 16, 59)) |
| 72 | +>T : Symbol(T, Decl(keyofIntersection.ts, 18, 14)) |
| 73 | +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) |
| 74 | +>T : Symbol(T, Decl(keyofIntersection.ts, 18, 14)) |
| 75 | + |
| 76 | +type Result3 = Example3<'x' | 'y'>; // "x" | "y" |
| 77 | +>Result3 : Symbol(Result3, Decl(keyofIntersection.ts, 18, 57)) |
| 78 | +>Example3 : Symbol(Example3, Decl(keyofIntersection.ts, 16, 59)) |
| 79 | + |
| 80 | +type Example4<T extends string, U extends string> = (Record<T, any> & Record<U, any>); |
| 81 | +>Example4 : Symbol(Example4, Decl(keyofIntersection.ts, 19, 35)) |
| 82 | +>T : Symbol(T, Decl(keyofIntersection.ts, 21, 14)) |
| 83 | +>U : Symbol(U, Decl(keyofIntersection.ts, 21, 31)) |
| 84 | +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) |
| 85 | +>T : Symbol(T, Decl(keyofIntersection.ts, 21, 14)) |
| 86 | +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) |
| 87 | +>U : Symbol(U, Decl(keyofIntersection.ts, 21, 31)) |
| 88 | + |
| 89 | +type Result4 = keyof Example4<'x', 'y'>; // "x" | "y" |
| 90 | +>Result4 : Symbol(Result4, Decl(keyofIntersection.ts, 21, 86)) |
| 91 | +>Example4 : Symbol(Example4, Decl(keyofIntersection.ts, 19, 35)) |
| 92 | + |
| 93 | +type Example5<T, U> = keyof (T & U); |
| 94 | +>Example5 : Symbol(Example5, Decl(keyofIntersection.ts, 22, 40)) |
| 95 | +>T : Symbol(T, Decl(keyofIntersection.ts, 24, 14)) |
| 96 | +>U : Symbol(U, Decl(keyofIntersection.ts, 24, 16)) |
| 97 | +>T : Symbol(T, Decl(keyofIntersection.ts, 24, 14)) |
| 98 | +>U : Symbol(U, Decl(keyofIntersection.ts, 24, 16)) |
| 99 | + |
| 100 | +type Result5 = Example5<Record<'x', any>, Record<'y', any>>; // "x" | "y" |
| 101 | +>Result5 : Symbol(Result5, Decl(keyofIntersection.ts, 24, 36)) |
| 102 | +>Example5 : Symbol(Example5, Decl(keyofIntersection.ts, 22, 40)) |
| 103 | +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) |
| 104 | +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) |
| 105 | + |
0 commit comments