mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Add extra test cases for indexed access on generic mapped type (#53112)
This commit is contained in:
committed by
GitHub
parent
43cc362cef
commit
9c7f43dfd8
@@ -268,7 +268,38 @@ const getStringAndNumberFromOriginalAndMapped = <
|
||||
nestedKey: N
|
||||
): [Original[K][N], MappedFromOriginal[K][N]] => {
|
||||
return [original[key][nestedKey], mappedFromOriginal[key][nestedKey]];
|
||||
};
|
||||
};
|
||||
|
||||
// repro from #31675
|
||||
interface Config {
|
||||
string: string;
|
||||
number: number;
|
||||
}
|
||||
|
||||
function getConfigOrDefault<T extends keyof Config>(
|
||||
userConfig: Partial<Config>,
|
||||
key: T,
|
||||
defaultValue: Config[T]
|
||||
): Config[T] {
|
||||
const userValue = userConfig[key];
|
||||
const assertedCheck = userValue ? userValue! : defaultValue;
|
||||
return assertedCheck;
|
||||
}
|
||||
|
||||
// repro from #47523
|
||||
|
||||
type Foo1 = {
|
||||
x: number;
|
||||
y: string;
|
||||
};
|
||||
|
||||
function getValueConcrete<K extends keyof Foo1>(
|
||||
o: Partial<Foo1>,
|
||||
k: K
|
||||
): Foo1[K] | undefined {
|
||||
return o[k];
|
||||
}
|
||||
|
||||
|
||||
//// [correlatedUnions.js]
|
||||
"use strict";
|
||||
@@ -392,6 +423,14 @@ var BAR_LOOKUP = makeCompleteLookupMapping(ALL_BARS, 'name');
|
||||
var getStringAndNumberFromOriginalAndMapped = function (original, mappedFromOriginal, key, nestedKey) {
|
||||
return [original[key][nestedKey], mappedFromOriginal[key][nestedKey]];
|
||||
};
|
||||
function getConfigOrDefault(userConfig, key, defaultValue) {
|
||||
var userValue = userConfig[key];
|
||||
var assertedCheck = userValue ? userValue : defaultValue;
|
||||
return assertedCheck;
|
||||
}
|
||||
function getValueConcrete(o, k) {
|
||||
return o[k];
|
||||
}
|
||||
|
||||
|
||||
//// [correlatedUnions.d.ts]
|
||||
@@ -562,3 +601,13 @@ type SameKeys<T> = {
|
||||
};
|
||||
type MappedFromOriginal = SameKeys<Original>;
|
||||
declare const getStringAndNumberFromOriginalAndMapped: <K extends keyof Original, N extends keyof Original[K]>(original: Original, mappedFromOriginal: MappedFromOriginal, key: K, nestedKey: N) => [Original[K][N], SameKeys<Original>[K][N]];
|
||||
interface Config {
|
||||
string: string;
|
||||
number: number;
|
||||
}
|
||||
declare function getConfigOrDefault<T extends keyof Config>(userConfig: Partial<Config>, key: T, defaultValue: Config[T]): Config[T];
|
||||
type Foo1 = {
|
||||
x: number;
|
||||
y: string;
|
||||
};
|
||||
declare function getValueConcrete<K extends keyof Foo1>(o: Partial<Foo1>, k: K): Foo1[K] | undefined;
|
||||
|
||||
@@ -928,3 +928,89 @@ const getStringAndNumberFromOriginalAndMapped = <
|
||||
>nestedKey : Symbol(nestedKey, Decl(correlatedUnions.ts, 265, 9))
|
||||
|
||||
};
|
||||
|
||||
// repro from #31675
|
||||
interface Config {
|
||||
>Config : Symbol(Config, Decl(correlatedUnions.ts, 269, 2))
|
||||
|
||||
string: string;
|
||||
>string : Symbol(Config.string, Decl(correlatedUnions.ts, 272, 18))
|
||||
|
||||
number: number;
|
||||
>number : Symbol(Config.number, Decl(correlatedUnions.ts, 273, 17))
|
||||
}
|
||||
|
||||
function getConfigOrDefault<T extends keyof Config>(
|
||||
>getConfigOrDefault : Symbol(getConfigOrDefault, Decl(correlatedUnions.ts, 275, 1))
|
||||
>T : Symbol(T, Decl(correlatedUnions.ts, 277, 28))
|
||||
>Config : Symbol(Config, Decl(correlatedUnions.ts, 269, 2))
|
||||
|
||||
userConfig: Partial<Config>,
|
||||
>userConfig : Symbol(userConfig, Decl(correlatedUnions.ts, 277, 52))
|
||||
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
|
||||
>Config : Symbol(Config, Decl(correlatedUnions.ts, 269, 2))
|
||||
|
||||
key: T,
|
||||
>key : Symbol(key, Decl(correlatedUnions.ts, 278, 30))
|
||||
>T : Symbol(T, Decl(correlatedUnions.ts, 277, 28))
|
||||
|
||||
defaultValue: Config[T]
|
||||
>defaultValue : Symbol(defaultValue, Decl(correlatedUnions.ts, 279, 9))
|
||||
>Config : Symbol(Config, Decl(correlatedUnions.ts, 269, 2))
|
||||
>T : Symbol(T, Decl(correlatedUnions.ts, 277, 28))
|
||||
|
||||
): Config[T] {
|
||||
>Config : Symbol(Config, Decl(correlatedUnions.ts, 269, 2))
|
||||
>T : Symbol(T, Decl(correlatedUnions.ts, 277, 28))
|
||||
|
||||
const userValue = userConfig[key];
|
||||
>userValue : Symbol(userValue, Decl(correlatedUnions.ts, 282, 7))
|
||||
>userConfig : Symbol(userConfig, Decl(correlatedUnions.ts, 277, 52))
|
||||
>key : Symbol(key, Decl(correlatedUnions.ts, 278, 30))
|
||||
|
||||
const assertedCheck = userValue ? userValue! : defaultValue;
|
||||
>assertedCheck : Symbol(assertedCheck, Decl(correlatedUnions.ts, 283, 7))
|
||||
>userValue : Symbol(userValue, Decl(correlatedUnions.ts, 282, 7))
|
||||
>userValue : Symbol(userValue, Decl(correlatedUnions.ts, 282, 7))
|
||||
>defaultValue : Symbol(defaultValue, Decl(correlatedUnions.ts, 279, 9))
|
||||
|
||||
return assertedCheck;
|
||||
>assertedCheck : Symbol(assertedCheck, Decl(correlatedUnions.ts, 283, 7))
|
||||
}
|
||||
|
||||
// repro from #47523
|
||||
|
||||
type Foo1 = {
|
||||
>Foo1 : Symbol(Foo1, Decl(correlatedUnions.ts, 285, 1))
|
||||
|
||||
x: number;
|
||||
>x : Symbol(x, Decl(correlatedUnions.ts, 289, 13))
|
||||
|
||||
y: string;
|
||||
>y : Symbol(y, Decl(correlatedUnions.ts, 290, 12))
|
||||
|
||||
};
|
||||
|
||||
function getValueConcrete<K extends keyof Foo1>(
|
||||
>getValueConcrete : Symbol(getValueConcrete, Decl(correlatedUnions.ts, 292, 2))
|
||||
>K : Symbol(K, Decl(correlatedUnions.ts, 294, 26))
|
||||
>Foo1 : Symbol(Foo1, Decl(correlatedUnions.ts, 285, 1))
|
||||
|
||||
o: Partial<Foo1>,
|
||||
>o : Symbol(o, Decl(correlatedUnions.ts, 294, 48))
|
||||
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
|
||||
>Foo1 : Symbol(Foo1, Decl(correlatedUnions.ts, 285, 1))
|
||||
|
||||
k: K
|
||||
>k : Symbol(k, Decl(correlatedUnions.ts, 295, 19))
|
||||
>K : Symbol(K, Decl(correlatedUnions.ts, 294, 26))
|
||||
|
||||
): Foo1[K] | undefined {
|
||||
>Foo1 : Symbol(Foo1, Decl(correlatedUnions.ts, 285, 1))
|
||||
>K : Symbol(K, Decl(correlatedUnions.ts, 294, 26))
|
||||
|
||||
return o[k];
|
||||
>o : Symbol(o, Decl(correlatedUnions.ts, 294, 48))
|
||||
>k : Symbol(k, Decl(correlatedUnions.ts, 295, 19))
|
||||
}
|
||||
|
||||
|
||||
@@ -828,3 +828,73 @@ const getStringAndNumberFromOriginalAndMapped = <
|
||||
>nestedKey : N
|
||||
|
||||
};
|
||||
|
||||
// repro from #31675
|
||||
interface Config {
|
||||
string: string;
|
||||
>string : string
|
||||
|
||||
number: number;
|
||||
>number : number
|
||||
}
|
||||
|
||||
function getConfigOrDefault<T extends keyof Config>(
|
||||
>getConfigOrDefault : <T extends keyof Config>(userConfig: Partial<Config>, key: T, defaultValue: Config[T]) => Config[T]
|
||||
|
||||
userConfig: Partial<Config>,
|
||||
>userConfig : Partial<Config>
|
||||
|
||||
key: T,
|
||||
>key : T
|
||||
|
||||
defaultValue: Config[T]
|
||||
>defaultValue : Config[T]
|
||||
|
||||
): Config[T] {
|
||||
const userValue = userConfig[key];
|
||||
>userValue : Partial<Config>[T]
|
||||
>userConfig[key] : Partial<Config>[T]
|
||||
>userConfig : Partial<Config>
|
||||
>key : T
|
||||
|
||||
const assertedCheck = userValue ? userValue! : defaultValue;
|
||||
>assertedCheck : Config[T]
|
||||
>userValue ? userValue! : defaultValue : Config[T]
|
||||
>userValue : Partial<Config>[T]
|
||||
>userValue! : NonNullable<Partial<Config>[T]>
|
||||
>userValue : NonNullable<Partial<Config>[T]>
|
||||
>defaultValue : Config[T]
|
||||
|
||||
return assertedCheck;
|
||||
>assertedCheck : Config[T]
|
||||
}
|
||||
|
||||
// repro from #47523
|
||||
|
||||
type Foo1 = {
|
||||
>Foo1 : { x: number; y: string; }
|
||||
|
||||
x: number;
|
||||
>x : number
|
||||
|
||||
y: string;
|
||||
>y : string
|
||||
|
||||
};
|
||||
|
||||
function getValueConcrete<K extends keyof Foo1>(
|
||||
>getValueConcrete : <K extends keyof Foo1>(o: Partial<Foo1>, k: K) => Foo1[K] | undefined
|
||||
|
||||
o: Partial<Foo1>,
|
||||
>o : Partial<Foo1>
|
||||
|
||||
k: K
|
||||
>k : K
|
||||
|
||||
): Foo1[K] | undefined {
|
||||
return o[k];
|
||||
>o[k] : Partial<Foo1>[K]
|
||||
>o : Partial<Foo1>
|
||||
>k : K
|
||||
}
|
||||
|
||||
|
||||
@@ -270,4 +270,34 @@ const getStringAndNumberFromOriginalAndMapped = <
|
||||
nestedKey: N
|
||||
): [Original[K][N], MappedFromOriginal[K][N]] => {
|
||||
return [original[key][nestedKey], mappedFromOriginal[key][nestedKey]];
|
||||
};
|
||||
};
|
||||
|
||||
// repro from #31675
|
||||
interface Config {
|
||||
string: string;
|
||||
number: number;
|
||||
}
|
||||
|
||||
function getConfigOrDefault<T extends keyof Config>(
|
||||
userConfig: Partial<Config>,
|
||||
key: T,
|
||||
defaultValue: Config[T]
|
||||
): Config[T] {
|
||||
const userValue = userConfig[key];
|
||||
const assertedCheck = userValue ? userValue! : defaultValue;
|
||||
return assertedCheck;
|
||||
}
|
||||
|
||||
// repro from #47523
|
||||
|
||||
type Foo1 = {
|
||||
x: number;
|
||||
y: string;
|
||||
};
|
||||
|
||||
function getValueConcrete<K extends keyof Foo1>(
|
||||
o: Partial<Foo1>,
|
||||
k: K
|
||||
): Foo1[K] | undefined {
|
||||
return o[k];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user