|
| 1 | +//// [tests/cases/compiler/intersectionConstraintReduction.ts] //// |
| 2 | + |
| 3 | +=== intersectionConstraintReduction.ts === |
| 4 | +type Test1<K1 extends keyof any, K2 extends keyof any> = |
| 5 | +>Test1 : Symbol(Test1, Decl(intersectionConstraintReduction.ts, 0, 0)) |
| 6 | +>K1 : Symbol(K1, Decl(intersectionConstraintReduction.ts, 0, 11)) |
| 7 | +>K2 : Symbol(K2, Decl(intersectionConstraintReduction.ts, 0, 32)) |
| 8 | + |
| 9 | + MustBeKey<Extract<K1, keyof any> & K1 & K2>; |
| 10 | +>MustBeKey : Symbol(MustBeKey, Decl(intersectionConstraintReduction.ts, 4, 48)) |
| 11 | +>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) |
| 12 | +>K1 : Symbol(K1, Decl(intersectionConstraintReduction.ts, 0, 11)) |
| 13 | +>K1 : Symbol(K1, Decl(intersectionConstraintReduction.ts, 0, 11)) |
| 14 | +>K2 : Symbol(K2, Decl(intersectionConstraintReduction.ts, 0, 32)) |
| 15 | + |
| 16 | +type Test2<K1 extends keyof any, K2 extends keyof any> = |
| 17 | +>Test2 : Symbol(Test2, Decl(intersectionConstraintReduction.ts, 1, 48)) |
| 18 | +>K1 : Symbol(K1, Decl(intersectionConstraintReduction.ts, 3, 11)) |
| 19 | +>K2 : Symbol(K2, Decl(intersectionConstraintReduction.ts, 3, 32)) |
| 20 | + |
| 21 | + MustBeKey<K1 & K2 & Extract<K1, keyof any>>; |
| 22 | +>MustBeKey : Symbol(MustBeKey, Decl(intersectionConstraintReduction.ts, 4, 48)) |
| 23 | +>K1 : Symbol(K1, Decl(intersectionConstraintReduction.ts, 3, 11)) |
| 24 | +>K2 : Symbol(K2, Decl(intersectionConstraintReduction.ts, 3, 32)) |
| 25 | +>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) |
| 26 | +>K1 : Symbol(K1, Decl(intersectionConstraintReduction.ts, 3, 11)) |
| 27 | + |
| 28 | +type MustBeKey<K extends keyof any> = K; |
| 29 | +>MustBeKey : Symbol(MustBeKey, Decl(intersectionConstraintReduction.ts, 4, 48)) |
| 30 | +>K : Symbol(K, Decl(intersectionConstraintReduction.ts, 6, 15)) |
| 31 | +>K : Symbol(K, Decl(intersectionConstraintReduction.ts, 6, 15)) |
| 32 | + |
| 33 | +// https://github.com/microsoft/TypeScript/issues/58370 |
| 34 | + |
| 35 | +type AnyKey = number | string | symbol; |
| 36 | +>AnyKey : Symbol(AnyKey, Decl(intersectionConstraintReduction.ts, 6, 40)) |
| 37 | + |
| 38 | +type ReturnTypeKeyof<Obj extends object> = Obj extends object |
| 39 | +>ReturnTypeKeyof : Symbol(ReturnTypeKeyof, Decl(intersectionConstraintReduction.ts, 10, 39)) |
| 40 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 12, 21)) |
| 41 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 12, 21)) |
| 42 | + |
| 43 | + ? [keyof Obj] extends [never] |
| 44 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 12, 21)) |
| 45 | + |
| 46 | + ? never |
| 47 | + : { [Key in keyof Obj as string]-?: () => Key }[string] |
| 48 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 15, 13)) |
| 49 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 12, 21)) |
| 50 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 15, 13)) |
| 51 | + |
| 52 | + : never; |
| 53 | + |
| 54 | +type KeyIfSignatureOfObject< |
| 55 | +>KeyIfSignatureOfObject : Symbol(KeyIfSignatureOfObject, Decl(intersectionConstraintReduction.ts, 16, 12)) |
| 56 | + |
| 57 | + Obj extends object, |
| 58 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 18, 28)) |
| 59 | + |
| 60 | + Key extends AnyKey, |
| 61 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 19, 23)) |
| 62 | +>AnyKey : Symbol(AnyKey, Decl(intersectionConstraintReduction.ts, 6, 40)) |
| 63 | + |
| 64 | + ReturnTypeKeys = ReturnTypeKeyof<Obj>, |
| 65 | +>ReturnTypeKeys : Symbol(ReturnTypeKeys, Decl(intersectionConstraintReduction.ts, 20, 23)) |
| 66 | +>ReturnTypeKeyof : Symbol(ReturnTypeKeyof, Decl(intersectionConstraintReduction.ts, 10, 39)) |
| 67 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 18, 28)) |
| 68 | + |
| 69 | +> = ReturnTypeKeys extends () => Key ? ((() => Key) extends ReturnTypeKeys ? Key : never) : never; |
| 70 | +>ReturnTypeKeys : Symbol(ReturnTypeKeys, Decl(intersectionConstraintReduction.ts, 20, 23)) |
| 71 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 19, 23)) |
| 72 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 19, 23)) |
| 73 | +>ReturnTypeKeys : Symbol(ReturnTypeKeys, Decl(intersectionConstraintReduction.ts, 20, 23)) |
| 74 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 19, 23)) |
| 75 | + |
| 76 | +export type Reduced1<Obj extends object, Key extends AnyKey, Value, ObjKeys extends keyof Obj = keyof Obj> = |
| 77 | +>Reduced1 : Symbol(Reduced1, Decl(intersectionConstraintReduction.ts, 22, 98)) |
| 78 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 24, 21)) |
| 79 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 24, 40)) |
| 80 | +>AnyKey : Symbol(AnyKey, Decl(intersectionConstraintReduction.ts, 6, 40)) |
| 81 | +>Value : Symbol(Value, Decl(intersectionConstraintReduction.ts, 24, 60)) |
| 82 | +>ObjKeys : Symbol(ObjKeys, Decl(intersectionConstraintReduction.ts, 24, 67)) |
| 83 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 24, 21)) |
| 84 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 24, 21)) |
| 85 | + |
| 86 | + Key extends KeyIfSignatureOfObject<Obj, Key> |
| 87 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 24, 40)) |
| 88 | +>KeyIfSignatureOfObject : Symbol(KeyIfSignatureOfObject, Decl(intersectionConstraintReduction.ts, 16, 12)) |
| 89 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 24, 21)) |
| 90 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 24, 40)) |
| 91 | + |
| 92 | + ? Key extends ObjKeys |
| 93 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 24, 40)) |
| 94 | +>ObjKeys : Symbol(ObjKeys, Decl(intersectionConstraintReduction.ts, 24, 67)) |
| 95 | + |
| 96 | + ? { [K in Key]: Value } |
| 97 | +>K : Symbol(K, Decl(intersectionConstraintReduction.ts, 27, 17)) |
| 98 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 24, 40)) |
| 99 | +>Value : Symbol(Value, Decl(intersectionConstraintReduction.ts, 24, 60)) |
| 100 | + |
| 101 | + : never |
| 102 | + : never; |
| 103 | + |
| 104 | +export type Reduced2<Obj extends object, Key extends AnyKey, Value, ObjKeys extends keyof Obj = keyof Obj> = |
| 105 | +>Reduced2 : Symbol(Reduced2, Decl(intersectionConstraintReduction.ts, 29, 16)) |
| 106 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 31, 21)) |
| 107 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 31, 40)) |
| 108 | +>AnyKey : Symbol(AnyKey, Decl(intersectionConstraintReduction.ts, 6, 40)) |
| 109 | +>Value : Symbol(Value, Decl(intersectionConstraintReduction.ts, 31, 60)) |
| 110 | +>ObjKeys : Symbol(ObjKeys, Decl(intersectionConstraintReduction.ts, 31, 67)) |
| 111 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 31, 21)) |
| 112 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 31, 21)) |
| 113 | + |
| 114 | + Key extends AnyKey |
| 115 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 31, 40)) |
| 116 | +>AnyKey : Symbol(AnyKey, Decl(intersectionConstraintReduction.ts, 6, 40)) |
| 117 | + |
| 118 | + ? Key extends KeyIfSignatureOfObject<Obj, Key> |
| 119 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 31, 40)) |
| 120 | +>KeyIfSignatureOfObject : Symbol(KeyIfSignatureOfObject, Decl(intersectionConstraintReduction.ts, 16, 12)) |
| 121 | +>Obj : Symbol(Obj, Decl(intersectionConstraintReduction.ts, 31, 21)) |
| 122 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 31, 40)) |
| 123 | + |
| 124 | + ? Key extends ObjKeys |
| 125 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 31, 40)) |
| 126 | +>ObjKeys : Symbol(ObjKeys, Decl(intersectionConstraintReduction.ts, 31, 67)) |
| 127 | + |
| 128 | + ? { [K in Key]: Value } |
| 129 | +>K : Symbol(K, Decl(intersectionConstraintReduction.ts, 35, 20)) |
| 130 | +>Key : Symbol(Key, Decl(intersectionConstraintReduction.ts, 31, 40)) |
| 131 | +>Value : Symbol(Value, Decl(intersectionConstraintReduction.ts, 31, 60)) |
| 132 | + |
| 133 | + : never |
| 134 | + : never |
| 135 | + : never; |
| 136 | + |
0 commit comments