Skip to content

Commit 8e6a2b1

Browse files
committed
Single point of creation for type mappers
1 parent 82cd7a1 commit 8e6a2b1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,9 @@ namespace ts {
728728
const keyofConstraintType = keyofStringsOnly ? stringType : stringNumberSymbolType;
729729
const numberOrBigIntType = getUnionType([numberType, bigintType]);
730730

731-
const identityMapper: TypeMapper = { kind: TypeMapKind.Function, func: t => t };
732-
const restrictiveMapper: TypeMapper = { kind: TypeMapKind.Function, func: t => t.flags & TypeFlags.TypeParameter ? getRestrictiveTypeParameter(<TypeParameter>t) : t };
733-
const permissiveMapper: TypeMapper = { kind: TypeMapKind.Function, func: t => t.flags & TypeFlags.TypeParameter ? wildcardType : t };
731+
const identityMapper: TypeMapper = makeFunctionTypeMapper(t => t);
732+
const restrictiveMapper: TypeMapper = makeFunctionTypeMapper(t => t.flags & TypeFlags.TypeParameter ? getRestrictiveTypeParameter(<TypeParameter>t) : t);
733+
const permissiveMapper: TypeMapper = makeFunctionTypeMapper(t => t.flags & TypeFlags.TypeParameter ? wildcardType : t);
734734

735735
const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
736736
const emptyJsxObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
@@ -13544,7 +13544,7 @@ namespace ts {
1354413544
function createTypeMapper(sources: readonly TypeParameter[], targets: readonly Type[] | undefined): TypeMapper {
1354513545
return sources.length === 1 ?
1354613546
makeUnaryTypeMapper(sources[0], targets ? targets[0] : anyType) :
13547-
{ kind: TypeMapKind.Multiple, sources, targets };
13547+
makeMultipleTypeMapper(sources, targets);
1354813548
}
1354913549

1355013550
function getMappedType(type: Type, map: TypeMapper): Type {
@@ -13569,6 +13569,10 @@ namespace ts {
1356913569
return { kind: TypeMapKind.Single, source, target };
1357013570
}
1357113571

13572+
function makeMultipleTypeMapper(sources: readonly TypeParameter[], targets: readonly Type[] | undefined): TypeMapper {
13573+
return { kind: TypeMapKind.Multiple, sources, targets };
13574+
}
13575+
1357213576
function makeFunctionTypeMapper(func: (t: Type) => Type): TypeMapper {
1357313577
return { kind: TypeMapKind.Function, func };
1357413578
}
@@ -13582,7 +13586,7 @@ namespace ts {
1358213586
* This is used during inference when instantiating type parameter defaults.
1358313587
*/
1358413588
function createBackreferenceMapper(context: InferenceContext, index: number): TypeMapper {
13585-
return { kind: TypeMapKind.Function, func: t => findIndex(context.inferences, info => info.typeParameter === t) >= index ? unknownType : t };
13589+
return makeFunctionTypeMapper(t => findIndex(context.inferences, info => info.typeParameter === t) >= index ? unknownType : t);
1358613590
}
1358713591

1358813592
function getTypeMapperSources(mapper: TypeMapper) {

0 commit comments

Comments
 (0)