mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Include index signatures of the source in mapped type template target inferences (#29253)
This commit is contained in:
@@ -14574,7 +14574,12 @@ namespace ts {
|
||||
priority |= InferencePriority.MappedTypeConstraint;
|
||||
inferFromTypes(getIndexType(source), constraintType);
|
||||
priority = savePriority;
|
||||
inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(<MappedType>target));
|
||||
const valueTypes = compact([
|
||||
getIndexTypeOfType(source, IndexKind.String),
|
||||
getIndexTypeOfType(source, IndexKind.Number),
|
||||
...map(getPropertiesOfType(source), getTypeOfSymbol)
|
||||
]);
|
||||
inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(<MappedType>target));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -884,8 +884,11 @@ namespace ts {
|
||||
/**
|
||||
* Compacts an array, removing any falsey elements.
|
||||
*/
|
||||
export function compact<T>(array: T[]): T[];
|
||||
export function compact<T>(array: ReadonlyArray<T>): ReadonlyArray<T>;
|
||||
export function compact<T>(array: (T | undefined | null | false | 0 | "")[]): T[];
|
||||
export function compact<T>(array: ReadonlyArray<T | undefined | null | false | 0 | "">): ReadonlyArray<T>;
|
||||
// TSLint thinks these can be combined with the above - they cannot; they'd produce higher-priority inferences and prevent the falsey types from being stripped
|
||||
export function compact<T>(array: T[]): T[]; // tslint:disable-line unified-signatures
|
||||
export function compact<T>(array: ReadonlyArray<T>): ReadonlyArray<T>; // tslint:disable-line unified-signatures
|
||||
export function compact<T>(array: T[]): T[] {
|
||||
let result: T[] | undefined;
|
||||
if (array) {
|
||||
|
||||
Reference in New Issue
Block a user