diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols index 36fb8d2989b..0e97ef793fb 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols @@ -268,3 +268,34 @@ function f20(k1: keyof (T | U), k2: keyof (T & U), o1: T | U, o2: T & U) { >k2 : Symbol(k2, Decl(keyofAndIndexedAccessErrors.ts, 69, 37)) >k1 : Symbol(k1, Decl(keyofAndIndexedAccessErrors.ts, 69, 19)) } + +// Repro from #17166 +function f3(obj: T, k: K, value: T[K]): void { +>f3 : Symbol(f3, Decl(keyofAndIndexedAccessErrors.ts, 78, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 81, 14)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccessErrors.ts, 81, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) +>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 81, 41)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 81, 14)) +>value : Symbol(value, Decl(keyofAndIndexedAccessErrors.ts, 81, 47)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 81, 14)) + + for (let key in obj) { +>key : Symbol(key, Decl(keyofAndIndexedAccessErrors.ts, 82, 12)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccessErrors.ts, 81, 34)) + + k = key // error, keyof T =/=> K +>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 81, 41)) +>key : Symbol(key, Decl(keyofAndIndexedAccessErrors.ts, 82, 12)) + + value = obj[key]; // error, T[keyof T] =/=> T[K] +>value : Symbol(value, Decl(keyofAndIndexedAccessErrors.ts, 81, 47)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccessErrors.ts, 81, 34)) +>key : Symbol(key, Decl(keyofAndIndexedAccessErrors.ts, 82, 12)) + } +} + + diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.types b/tests/baselines/reference/keyofAndIndexedAccessErrors.types index 4d2e25641d3..f5cc7c093d9 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.types +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.types @@ -299,3 +299,37 @@ function f20(k1: keyof (T | U), k2: keyof (T & U), o1: T | U, o2: T & U) { >k2 : keyof (T & U) >k1 : keyof (T | U) } + +// Repro from #17166 +function f3(obj: T, k: K, value: T[K]): void { +>f3 : (obj: T, k: K, value: T[K]) => void +>T : T +>K : K +>T : T +>obj : T +>T : T +>k : K +>K : K +>value : T[K] +>T : T +>K : K + + for (let key in obj) { +>key : keyof T +>obj : T + + k = key // error, keyof T =/=> K +>k = key : keyof T +>k : K +>key : keyof T + + value = obj[key]; // error, T[keyof T] =/=> T[K] +>value = obj[key] : T[keyof T] +>value : T[K] +>obj[key] : T[keyof T] +>obj : T +>key : keyof T + } +} + + diff --git a/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.symbols b/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.symbols new file mode 100644 index 00000000000..3ada1e3f3d1 --- /dev/null +++ b/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.symbols @@ -0,0 +1,145 @@ +=== tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts === +// test for #15371 +function f(s: string, tp: T[P]): void { +>f : Symbol(f, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 0, 0)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 1, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 1, 28)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 1, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 1, 48)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 1, 58)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 1, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 1, 28)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 1, 58)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 1, 48)) +} +function g(s: string, tp: T[P]): void { +>g : Symbol(g, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 3, 1)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 4, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 4, 26)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 4, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 4, 46)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 4, 56)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 4, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 4, 26)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 4, 56)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 4, 46)) +} +function h(s: string, tp: T[P]): void { +>h : Symbol(h, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 6, 1)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 7, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 7, 31)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 7, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 7, 51)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 7, 61)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 7, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 7, 31)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 7, 61)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 7, 51)) +} +function i(s: string, tp: T[P]): void { +>i : Symbol(i, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 9, 1)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 10, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 10, 26)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 10, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 10, 46)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 10, 56)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 10, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 10, 26)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 10, 56)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 10, 46)) +} +function j(s: string, tp: T[P]): void { +>j : Symbol(j, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 12, 1)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 13, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 13, 27)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 13, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 13, 47)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 13, 57)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 13, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 13, 27)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 13, 57)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 13, 47)) +} +function k(s: string, tp: T[P]): void { +>k : Symbol(k, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 15, 1)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 16, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 16, 28)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 16, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 16, 48)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 16, 58)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 16, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 16, 28)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 16, 58)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 16, 48)) +} +function o(s: string, tp: T[P]): void { +>o : Symbol(o, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 18, 1)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 19, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 19, 28)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 19, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 19, 48)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 19, 58)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 19, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 19, 28)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 19, 58)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 19, 48)) +} +function l(s: string, tp: T[P]): void { +>l : Symbol(l, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 21, 1)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 22, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 22, 24)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 22, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 22, 44)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 22, 54)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 22, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 22, 24)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 22, 54)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 22, 44)) +} +function m(s: string, tp: T[P]): void { +>m : Symbol(m, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 24, 1)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 11)) +>a : Symbol(a, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 22)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 35)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 55)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 65)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 35)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 65)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 25, 55)) +} +function n(s: string, tp: T[P]): void { +>n : Symbol(n, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 27, 1)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 24)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 45)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 11)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 65)) +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 75)) +>T : Symbol(T, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 11)) +>P : Symbol(P, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 45)) + + tp = s; +>tp : Symbol(tp, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 75)) +>s : Symbol(s, Decl(nonPrimitiveConstraintOfIndexAccessType.ts, 28, 65)) +} + diff --git a/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.types b/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.types new file mode 100644 index 00000000000..d5e8560d7cf --- /dev/null +++ b/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.types @@ -0,0 +1,156 @@ +=== tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts === +// test for #15371 +function f(s: string, tp: T[P]): void { +>f : (s: string, tp: T[P]) => void +>T : T +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +function g(s: string, tp: T[P]): void { +>g : (s: string, tp: T[P]) => void +>T : T +>null : null +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +function h(s: string, tp: T[P]): void { +>h : (s: string, tp: T[P]) => void +>T : T +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +function i(s: string, tp: T[P]): void { +>i : (s: string, tp: T[P]) => void +>T : T +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +function j(s: string, tp: T[P]): void { +>j : (s: string, tp: T[P]) => void +>T : T +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +function k(s: string, tp: T[P]): void { +>k : (s: string, tp: T[P]) => void +>T : T +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +function o(s: string, tp: T[P]): void { +>o : (s: string, tp: T[P]) => void +>T : T +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +function l(s: string, tp: T[P]): void { +>l : (s: string, tp: T[P]) => void +>T : T +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +function m(s: string, tp: T[P]): void { +>m : (s: string, tp: T[P]) => void +>T : T +>a : number +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +function n(s: string, tp: T[P]): void { +>n : (s: string, tp: T[P]) => void +>T : T +>s : string +>P : P +>T : T +>s : string +>tp : T[P] +>T : T +>P : P + + tp = s; +>tp = s : string +>tp : T[P] +>s : string +} +