mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Add regression test
This commit is contained in:
parent
fc641fa275
commit
81e891812e
@ -463,6 +463,33 @@ let MyThingy: { [key in KeyTypes]: string[] };
|
||||
function addToMyThingy<S extends KeyTypes>(key: S) {
|
||||
MyThingy[key].push("a");
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds<T extends Record<K, string>, K extends string>(
|
||||
obj: T,
|
||||
idFields: K[],
|
||||
idMapping: { [oldId: string]: string }
|
||||
): Record<K, string> {
|
||||
for (const idField of idFields) {
|
||||
const newId = idMapping[obj[idField]];
|
||||
if (newId) {
|
||||
obj[idField] = newId;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
|
||||
obj: T,
|
||||
key: K,
|
||||
stringMap: { [oldId: string]: string }
|
||||
) {
|
||||
var x = obj[key];
|
||||
stringMap[x]; // Should be OK.
|
||||
}
|
||||
|
||||
|
||||
//// [keyofAndIndexedAccess.js]
|
||||
@ -769,6 +796,22 @@ var MyThingy;
|
||||
function addToMyThingy(key) {
|
||||
MyThingy[key].push("a");
|
||||
}
|
||||
// Repro from #13285
|
||||
function updateIds(obj, idFields, idMapping) {
|
||||
for (var _i = 0, idFields_1 = idFields; _i < idFields_1.length; _i++) {
|
||||
var idField = idFields_1[_i];
|
||||
var newId = idMapping[obj[idField]];
|
||||
if (newId) {
|
||||
obj[idField] = newId;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
// Repro from #13285
|
||||
function updateIds2(obj, key, stringMap) {
|
||||
var x = obj[key];
|
||||
stringMap[x]; // Should be OK.
|
||||
}
|
||||
|
||||
|
||||
//// [keyofAndIndexedAccess.d.ts]
|
||||
@ -986,3 +1029,11 @@ declare let MyThingy: {
|
||||
[key in KeyTypes]: string[];
|
||||
};
|
||||
declare function addToMyThingy<S extends KeyTypes>(key: S): void;
|
||||
declare function updateIds<T extends Record<K, string>, K extends string>(obj: T, idFields: K[], idMapping: {
|
||||
[oldId: string]: string;
|
||||
}): Record<K, string>;
|
||||
declare function updateIds2<T extends {
|
||||
[x: string]: string;
|
||||
}, K extends keyof T>(obj: T, key: K, stringMap: {
|
||||
[oldId: string]: string;
|
||||
}): void;
|
||||
|
||||
@ -1699,3 +1699,83 @@ function addToMyThingy<S extends KeyTypes>(key: S) {
|
||||
>push : Symbol(Array.push, Decl(lib.d.ts, --, --))
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds<T extends Record<K, string>, K extends string>(
|
||||
>updateIds : Symbol(updateIds, Decl(keyofAndIndexedAccess.ts, 463, 1))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 467, 19))
|
||||
>Record : Symbol(Record, Decl(lib.d.ts, --, --))
|
||||
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 467, 47))
|
||||
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 467, 47))
|
||||
|
||||
obj: T,
|
||||
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 467, 66))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 467, 19))
|
||||
|
||||
idFields: K[],
|
||||
>idFields : Symbol(idFields, Decl(keyofAndIndexedAccess.ts, 468, 11))
|
||||
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 467, 47))
|
||||
|
||||
idMapping: { [oldId: string]: string }
|
||||
>idMapping : Symbol(idMapping, Decl(keyofAndIndexedAccess.ts, 469, 18))
|
||||
>oldId : Symbol(oldId, Decl(keyofAndIndexedAccess.ts, 470, 18))
|
||||
|
||||
): Record<K, string> {
|
||||
>Record : Symbol(Record, Decl(lib.d.ts, --, --))
|
||||
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 467, 47))
|
||||
|
||||
for (const idField of idFields) {
|
||||
>idField : Symbol(idField, Decl(keyofAndIndexedAccess.ts, 472, 14))
|
||||
>idFields : Symbol(idFields, Decl(keyofAndIndexedAccess.ts, 468, 11))
|
||||
|
||||
const newId = idMapping[obj[idField]];
|
||||
>newId : Symbol(newId, Decl(keyofAndIndexedAccess.ts, 473, 13))
|
||||
>idMapping : Symbol(idMapping, Decl(keyofAndIndexedAccess.ts, 469, 18))
|
||||
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 467, 66))
|
||||
>idField : Symbol(idField, Decl(keyofAndIndexedAccess.ts, 472, 14))
|
||||
|
||||
if (newId) {
|
||||
>newId : Symbol(newId, Decl(keyofAndIndexedAccess.ts, 473, 13))
|
||||
|
||||
obj[idField] = newId;
|
||||
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 467, 66))
|
||||
>idField : Symbol(idField, Decl(keyofAndIndexedAccess.ts, 472, 14))
|
||||
>newId : Symbol(newId, Decl(keyofAndIndexedAccess.ts, 473, 13))
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 467, 66))
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
|
||||
>updateIds2 : Symbol(updateIds2, Decl(keyofAndIndexedAccess.ts, 479, 1))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 483, 20))
|
||||
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 483, 33))
|
||||
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 483, 54))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 483, 20))
|
||||
|
||||
obj: T,
|
||||
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 483, 74))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 483, 20))
|
||||
|
||||
key: K,
|
||||
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 484, 11))
|
||||
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 483, 54))
|
||||
|
||||
stringMap: { [oldId: string]: string }
|
||||
>stringMap : Symbol(stringMap, Decl(keyofAndIndexedAccess.ts, 485, 11))
|
||||
>oldId : Symbol(oldId, Decl(keyofAndIndexedAccess.ts, 486, 18))
|
||||
|
||||
) {
|
||||
var x = obj[key];
|
||||
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 488, 7))
|
||||
>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 483, 74))
|
||||
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 484, 11))
|
||||
|
||||
stringMap[x]; // Should be OK.
|
||||
>stringMap : Symbol(stringMap, Decl(keyofAndIndexedAccess.ts, 485, 11))
|
||||
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 488, 7))
|
||||
}
|
||||
|
||||
|
||||
@ -2013,3 +2013,89 @@ function addToMyThingy<S extends KeyTypes>(key: S) {
|
||||
>"a" : "a"
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds<T extends Record<K, string>, K extends string>(
|
||||
>updateIds : <T extends Record<K, string>, K extends string>(obj: T, idFields: K[], idMapping: { [oldId: string]: string; }) => Record<K, string>
|
||||
>T : T
|
||||
>Record : Record<K, T>
|
||||
>K : K
|
||||
>K : K
|
||||
|
||||
obj: T,
|
||||
>obj : T
|
||||
>T : T
|
||||
|
||||
idFields: K[],
|
||||
>idFields : K[]
|
||||
>K : K
|
||||
|
||||
idMapping: { [oldId: string]: string }
|
||||
>idMapping : { [oldId: string]: string; }
|
||||
>oldId : string
|
||||
|
||||
): Record<K, string> {
|
||||
>Record : Record<K, T>
|
||||
>K : K
|
||||
|
||||
for (const idField of idFields) {
|
||||
>idField : K
|
||||
>idFields : K[]
|
||||
|
||||
const newId = idMapping[obj[idField]];
|
||||
>newId : { [oldId: string]: string; }[T[K]]
|
||||
>idMapping[obj[idField]] : { [oldId: string]: string; }[T[K]]
|
||||
>idMapping : { [oldId: string]: string; }
|
||||
>obj[idField] : T[K]
|
||||
>obj : T
|
||||
>idField : K
|
||||
|
||||
if (newId) {
|
||||
>newId : { [oldId: string]: string; }[T[K]]
|
||||
|
||||
obj[idField] = newId;
|
||||
>obj[idField] = newId : { [oldId: string]: string; }[T[K]]
|
||||
>obj[idField] : T[K]
|
||||
>obj : T
|
||||
>idField : K
|
||||
>newId : { [oldId: string]: string; }[T[K]]
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
>obj : T
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
|
||||
>updateIds2 : <T extends { [x: string]: string; }, K extends keyof T>(obj: T, key: K, stringMap: { [oldId: string]: string; }) => void
|
||||
>T : T
|
||||
>x : string
|
||||
>K : K
|
||||
>T : T
|
||||
|
||||
obj: T,
|
||||
>obj : T
|
||||
>T : T
|
||||
|
||||
key: K,
|
||||
>key : K
|
||||
>K : K
|
||||
|
||||
stringMap: { [oldId: string]: string }
|
||||
>stringMap : { [oldId: string]: string; }
|
||||
>oldId : string
|
||||
|
||||
) {
|
||||
var x = obj[key];
|
||||
>x : T[K]
|
||||
>obj[key] : T[K]
|
||||
>obj : T
|
||||
>key : K
|
||||
|
||||
stringMap[x]; // Should be OK.
|
||||
>stringMap[x] : { [oldId: string]: string; }[T[K]]
|
||||
>stringMap : { [oldId: string]: string; }
|
||||
>x : T[K]
|
||||
}
|
||||
|
||||
|
||||
@ -464,3 +464,30 @@ let MyThingy: { [key in KeyTypes]: string[] };
|
||||
function addToMyThingy<S extends KeyTypes>(key: S) {
|
||||
MyThingy[key].push("a");
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds<T extends Record<K, string>, K extends string>(
|
||||
obj: T,
|
||||
idFields: K[],
|
||||
idMapping: { [oldId: string]: string }
|
||||
): Record<K, string> {
|
||||
for (const idField of idFields) {
|
||||
const newId = idMapping[obj[idField]];
|
||||
if (newId) {
|
||||
obj[idField] = newId;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
|
||||
obj: T,
|
||||
key: K,
|
||||
stringMap: { [oldId: string]: string }
|
||||
) {
|
||||
var x = obj[key];
|
||||
stringMap[x]; // Should be OK.
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user