|
| 1 | +=== tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts === |
| 2 | +// From original issue #45212: |
| 3 | +type Methods<T> = { [P in keyof T as T[P] extends Function ? P : never]: T[P] }; |
| 4 | +>Methods : Symbol(Methods, Decl(mappedTypeAsClauseRelationships.ts, 0, 0)) |
| 5 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 1, 13)) |
| 6 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 1, 21)) |
| 7 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 1, 13)) |
| 8 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 1, 13)) |
| 9 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 1, 21)) |
| 10 | +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) |
| 11 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 1, 21)) |
| 12 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 1, 13)) |
| 13 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 1, 21)) |
| 14 | + |
| 15 | +type H<T> = T[keyof Methods<T>]; // Ok |
| 16 | +>H : Symbol(H, Decl(mappedTypeAsClauseRelationships.ts, 1, 80)) |
| 17 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 2, 7)) |
| 18 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 2, 7)) |
| 19 | +>Methods : Symbol(Methods, Decl(mappedTypeAsClauseRelationships.ts, 0, 0)) |
| 20 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 2, 7)) |
| 21 | + |
| 22 | +// `Filter<T>` only filters out some keys of `T`. |
| 23 | +type Filter<T> = { [P in keyof T as T[P] extends Function ? P : never]: T[P] }; |
| 24 | +>Filter : Symbol(Filter, Decl(mappedTypeAsClauseRelationships.ts, 2, 32)) |
| 25 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 5, 12)) |
| 26 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 5, 20)) |
| 27 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 5, 12)) |
| 28 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 5, 12)) |
| 29 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 5, 20)) |
| 30 | +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) |
| 31 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 5, 20)) |
| 32 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 5, 12)) |
| 33 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 5, 20)) |
| 34 | + |
| 35 | +// `Modify<T>` might modify some keys of `T`. |
| 36 | +type Modify<T> = { [P in keyof T as P extends string? `bool${P}`: P]: T[P] }; |
| 37 | +>Modify : Symbol(Modify, Decl(mappedTypeAsClauseRelationships.ts, 5, 79)) |
| 38 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 7, 12)) |
| 39 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 7, 20)) |
| 40 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 7, 12)) |
| 41 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 7, 20)) |
| 42 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 7, 20)) |
| 43 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 7, 20)) |
| 44 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 7, 12)) |
| 45 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 7, 20)) |
| 46 | + |
| 47 | +function fun<T>(val: T) { |
| 48 | +>fun : Symbol(fun, Decl(mappedTypeAsClauseRelationships.ts, 7, 77)) |
| 49 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 9, 13)) |
| 50 | +>val : Symbol(val, Decl(mappedTypeAsClauseRelationships.ts, 9, 16)) |
| 51 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 9, 13)) |
| 52 | + |
| 53 | + let x: Filter<T> = val; // Ok |
| 54 | +>x : Symbol(x, Decl(mappedTypeAsClauseRelationships.ts, 10, 7)) |
| 55 | +>Filter : Symbol(Filter, Decl(mappedTypeAsClauseRelationships.ts, 2, 32)) |
| 56 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 9, 13)) |
| 57 | +>val : Symbol(val, Decl(mappedTypeAsClauseRelationships.ts, 9, 16)) |
| 58 | + |
| 59 | + let y: Modify<T> = val; // Error |
| 60 | +>y : Symbol(y, Decl(mappedTypeAsClauseRelationships.ts, 11, 7)) |
| 61 | +>Modify : Symbol(Modify, Decl(mappedTypeAsClauseRelationships.ts, 5, 79)) |
| 62 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 9, 13)) |
| 63 | +>val : Symbol(val, Decl(mappedTypeAsClauseRelationships.ts, 9, 16)) |
| 64 | +} |
| 65 | + |
| 66 | +type FilterInclOpt<T> = { [P in keyof T as T[P] extends Function ? P : never]+?: T[P] }; |
| 67 | +>FilterInclOpt : Symbol(FilterInclOpt, Decl(mappedTypeAsClauseRelationships.ts, 12, 1)) |
| 68 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 14, 19)) |
| 69 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 14, 27)) |
| 70 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 14, 19)) |
| 71 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 14, 19)) |
| 72 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 14, 27)) |
| 73 | +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) |
| 74 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 14, 27)) |
| 75 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 14, 19)) |
| 76 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 14, 27)) |
| 77 | + |
| 78 | +type ModifyInclOpt<T> = { [P in keyof T as P extends string? `bool${P}`: never ]+?: T[P] }; |
| 79 | +>ModifyInclOpt : Symbol(ModifyInclOpt, Decl(mappedTypeAsClauseRelationships.ts, 14, 88)) |
| 80 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 15, 19)) |
| 81 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 15, 27)) |
| 82 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 15, 19)) |
| 83 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 15, 27)) |
| 84 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 15, 27)) |
| 85 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 15, 19)) |
| 86 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 15, 27)) |
| 87 | + |
| 88 | +type FilterExclOpt<T> = { [P in keyof T as T[P] extends Function ? P : never]-?: T[P] }; |
| 89 | +>FilterExclOpt : Symbol(FilterExclOpt, Decl(mappedTypeAsClauseRelationships.ts, 15, 91)) |
| 90 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 16, 19)) |
| 91 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 16, 27)) |
| 92 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 16, 19)) |
| 93 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 16, 19)) |
| 94 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 16, 27)) |
| 95 | +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) |
| 96 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 16, 27)) |
| 97 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 16, 19)) |
| 98 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 16, 27)) |
| 99 | + |
| 100 | +type ModifyExclOpt<T> = { [P in keyof T as P extends string? `bool${P}`: never ]-?: T[P] }; |
| 101 | +>ModifyExclOpt : Symbol(ModifyExclOpt, Decl(mappedTypeAsClauseRelationships.ts, 16, 88)) |
| 102 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 17, 19)) |
| 103 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 17, 27)) |
| 104 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 17, 19)) |
| 105 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 17, 27)) |
| 106 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 17, 27)) |
| 107 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 17, 19)) |
| 108 | +>P : Symbol(P, Decl(mappedTypeAsClauseRelationships.ts, 17, 27)) |
| 109 | + |
| 110 | +function fun2<T>(val: T) { |
| 111 | +>fun2 : Symbol(fun2, Decl(mappedTypeAsClauseRelationships.ts, 17, 91)) |
| 112 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 19, 14)) |
| 113 | +>val : Symbol(val, Decl(mappedTypeAsClauseRelationships.ts, 19, 17)) |
| 114 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 19, 14)) |
| 115 | + |
| 116 | + let x: FilterInclOpt<T> = val; // Ok |
| 117 | +>x : Symbol(x, Decl(mappedTypeAsClauseRelationships.ts, 20, 7)) |
| 118 | +>FilterInclOpt : Symbol(FilterInclOpt, Decl(mappedTypeAsClauseRelationships.ts, 12, 1)) |
| 119 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 19, 14)) |
| 120 | +>val : Symbol(val, Decl(mappedTypeAsClauseRelationships.ts, 19, 17)) |
| 121 | + |
| 122 | + let y: ModifyInclOpt<T> = val; // Ok |
| 123 | +>y : Symbol(y, Decl(mappedTypeAsClauseRelationships.ts, 21, 7)) |
| 124 | +>ModifyInclOpt : Symbol(ModifyInclOpt, Decl(mappedTypeAsClauseRelationships.ts, 14, 88)) |
| 125 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 19, 14)) |
| 126 | +>val : Symbol(val, Decl(mappedTypeAsClauseRelationships.ts, 19, 17)) |
| 127 | + |
| 128 | + let z: FilterExclOpt<T> = val; // Error |
| 129 | +>z : Symbol(z, Decl(mappedTypeAsClauseRelationships.ts, 22, 7)) |
| 130 | +>FilterExclOpt : Symbol(FilterExclOpt, Decl(mappedTypeAsClauseRelationships.ts, 15, 91)) |
| 131 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 19, 14)) |
| 132 | +>val : Symbol(val, Decl(mappedTypeAsClauseRelationships.ts, 19, 17)) |
| 133 | + |
| 134 | + let w: ModifyExclOpt<T> = val; // Error |
| 135 | +>w : Symbol(w, Decl(mappedTypeAsClauseRelationships.ts, 23, 7)) |
| 136 | +>ModifyExclOpt : Symbol(ModifyExclOpt, Decl(mappedTypeAsClauseRelationships.ts, 16, 88)) |
| 137 | +>T : Symbol(T, Decl(mappedTypeAsClauseRelationships.ts, 19, 14)) |
| 138 | +>val : Symbol(val, Decl(mappedTypeAsClauseRelationships.ts, 19, 17)) |
| 139 | +} |
| 140 | + |
| 141 | + |
| 142 | + |
0 commit comments