|
| 1 | +//// [tests/cases/compiler/indexMappedTypeWithFilteredKeysWithNegation.ts] //// |
| 2 | + |
| 3 | +=== indexMappedTypeWithFilteredKeysWithNegation.ts === |
| 4 | +// homomorphic - mapped type causes `keyof ExcludeKey` to not simplify, relater operates with full mapped type awareness |
| 5 | +type ExcludeKey<T, TKey> = { |
| 6 | +>ExcludeKey : Symbol(ExcludeKey, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 0, 0)) |
| 7 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 1, 16)) |
| 8 | +>TKey : Symbol(TKey, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 1, 18)) |
| 9 | + |
| 10 | + [K in keyof T as K extends TKey ? never : K]: T[K] |
| 11 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 2, 5)) |
| 12 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 1, 16)) |
| 13 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 2, 5)) |
| 14 | +>TKey : Symbol(TKey, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 1, 18)) |
| 15 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 2, 5)) |
| 16 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 1, 16)) |
| 17 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 2, 5)) |
| 18 | + |
| 19 | +}; |
| 20 | + |
| 21 | +interface Test { |
| 22 | +>Test : Symbol(Test, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 3, 2)) |
| 23 | + |
| 24 | + a: string; |
| 25 | +>a : Symbol(Test.a, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 5, 16)) |
| 26 | + |
| 27 | + b: number; |
| 28 | +>b : Symbol(Test.b, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 6, 14)) |
| 29 | + |
| 30 | + c: boolean; |
| 31 | +>c : Symbol(Test.c, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 7, 14)) |
| 32 | +} |
| 33 | + |
| 34 | +declare const test: ExcludeKey<Test, "b">; |
| 35 | +>test : Symbol(test, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 11, 13)) |
| 36 | +>ExcludeKey : Symbol(ExcludeKey, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 0, 0)) |
| 37 | +>Test : Symbol(Test, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 3, 2)) |
| 38 | + |
| 39 | +declare var possibleKey: string & keyof Test & not "b"; |
| 40 | +>possibleKey : Symbol(possibleKey, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 12, 11)) |
| 41 | +>Test : Symbol(Test, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 3, 2)) |
| 42 | + |
| 43 | +test[possibleKey]; |
| 44 | +>test : Symbol(test, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 11, 13)) |
| 45 | +>possibleKey : Symbol(possibleKey, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 12, 11)) |
| 46 | + |
| 47 | +function f<T extends Test>(test: ExcludeKey<T, "b">, possibleKey: string & keyof T & not "b") { |
| 48 | +>f : Symbol(f, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 14, 18)) |
| 49 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 16, 11)) |
| 50 | +>Test : Symbol(Test, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 3, 2)) |
| 51 | +>test : Symbol(test, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 16, 27)) |
| 52 | +>ExcludeKey : Symbol(ExcludeKey, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 0, 0)) |
| 53 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 16, 11)) |
| 54 | +>possibleKey : Symbol(possibleKey, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 16, 52)) |
| 55 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 16, 11)) |
| 56 | + |
| 57 | + test[possibleKey]; |
| 58 | +>test : Symbol(test, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 16, 27)) |
| 59 | +>possibleKey : Symbol(possibleKey, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 16, 52)) |
| 60 | +} |
| 61 | + |
| 62 | +// non-homomorphic - mapped type declared with `keyof T & string` causes `keyof PathTuples` to simplify to `(keyof T & string) extends '_key' ? never : (keyof T & string)` |
| 63 | +// relater must operate without mapped type awareness |
| 64 | +// ultimate comparison is `keyof T & string & not '_key'` to `(keyof T & string) extends '_key' ? never : (keyof T & string)` |
| 65 | +type LocalExclude<T, U> = T & not U; |
| 66 | +>LocalExclude : Symbol(LocalExclude, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 18, 1)) |
| 67 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 23, 18)) |
| 68 | +>U : Symbol(U, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 23, 20)) |
| 69 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 23, 18)) |
| 70 | +>U : Symbol(U, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 23, 20)) |
| 71 | + |
| 72 | +type ChildPaths<T> = [PathTuples<T>] extends [never] ? [] : PathTuples<T>; |
| 73 | +>ChildPaths : Symbol(ChildPaths, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 23, 36)) |
| 74 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 24, 16)) |
| 75 | +>PathTuples : Symbol(PathTuples, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 24, 74)) |
| 76 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 24, 16)) |
| 77 | +>PathTuples : Symbol(PathTuples, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 24, 74)) |
| 78 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 24, 16)) |
| 79 | + |
| 80 | +type PathTuples<T> = T extends object |
| 81 | +>PathTuples : Symbol(PathTuples, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 24, 74)) |
| 82 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 25, 16)) |
| 83 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 25, 16)) |
| 84 | + |
| 85 | + ? { |
| 86 | + [K in keyof T & string as K extends '_key' ? never : K]: [PathTuples<T[K]>] extends [never] |
| 87 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 27, 7)) |
| 88 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 25, 16)) |
| 89 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 27, 7)) |
| 90 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 27, 7)) |
| 91 | +>PathTuples : Symbol(PathTuples, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 24, 74)) |
| 92 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 25, 16)) |
| 93 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 27, 7)) |
| 94 | + |
| 95 | + ? never |
| 96 | + : readonly [K, ...ChildPaths<T[K]>]; |
| 97 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 27, 7)) |
| 98 | +>ChildPaths : Symbol(ChildPaths, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 23, 36)) |
| 99 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 25, 16)) |
| 100 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 27, 7)) |
| 101 | + |
| 102 | + }[LocalExclude<keyof T & string, '_key'>] |
| 103 | +>LocalExclude : Symbol(LocalExclude, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 18, 1)) |
| 104 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 25, 16)) |
| 105 | + |
| 106 | + : []; |
| 107 | + |
| 108 | +type T1 = PathTuples<{ a: string; _key: string; b: { c: number } }>; |
| 109 | +>T1 : Symbol(T1, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 31, 7)) |
| 110 | +>PathTuples : Symbol(PathTuples, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 24, 74)) |
| 111 | +>a : Symbol(a, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 33, 22)) |
| 112 | +>_key : Symbol(_key, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 33, 33)) |
| 113 | +>b : Symbol(b, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 33, 47)) |
| 114 | +>c : Symbol(c, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 33, 52)) |
| 115 | + |
| 116 | +const t1: T1 = ['b', 'c']; |
| 117 | +>t1 : Symbol(t1, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 34, 5)) |
| 118 | +>T1 : Symbol(T1, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 31, 7)) |
| 119 | + |
| 120 | +type S1<T> = { [K in keyof T & string as K extends '_key' ? never : K]: 1 }[LocalExclude<keyof T & string, '_key'>]; |
| 121 | +>S1 : Symbol(S1, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 34, 26)) |
| 122 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 36, 8)) |
| 123 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 36, 16)) |
| 124 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 36, 8)) |
| 125 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 36, 16)) |
| 126 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 36, 16)) |
| 127 | +>LocalExclude : Symbol(LocalExclude, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 18, 1)) |
| 128 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 36, 8)) |
| 129 | + |
| 130 | +type S2<T> = { [K in string & keyof T as K extends '_key' ? never : K]: 1 }[LocalExclude<string & keyof T, '_key'>]; |
| 131 | +>S2 : Symbol(S2, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 36, 116)) |
| 132 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 37, 8)) |
| 133 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 37, 16)) |
| 134 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 37, 8)) |
| 135 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 37, 16)) |
| 136 | +>K : Symbol(K, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 37, 16)) |
| 137 | +>LocalExclude : Symbol(LocalExclude, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 18, 1)) |
| 138 | +>T : Symbol(T, Decl(indexMappedTypeWithFilteredKeysWithNegation.ts, 37, 8)) |
| 139 | + |
0 commit comments