diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7314f3c7961a7..bbc7108589340 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -47,6 +47,7 @@ import { Block, BooleanLiteral, BreakOrContinueStatement, + CalculationType, CallChain, CallExpression, CallLikeExpression, @@ -1398,14 +1399,35 @@ const enum IntrinsicTypeKind { Capitalize, Uncapitalize, NoInfer, + Add, + Sub, + Mul, + Div, + Floor, + Ceil, + Round, } +// Set.has is faster than Array.includes +const intrinsicUnaryKinds = new Set([ + IntrinsicTypeKind.Floor, + IntrinsicTypeKind.Ceil, + IntrinsicTypeKind.Round, +]); + const intrinsicTypeKinds: ReadonlyMap = new Map(Object.entries({ Uppercase: IntrinsicTypeKind.Uppercase, Lowercase: IntrinsicTypeKind.Lowercase, Capitalize: IntrinsicTypeKind.Capitalize, Uncapitalize: IntrinsicTypeKind.Uncapitalize, NoInfer: IntrinsicTypeKind.NoInfer, + Add: IntrinsicTypeKind.Add, + Subtract: IntrinsicTypeKind.Sub, + Multiply: IntrinsicTypeKind.Mul, + Divide: IntrinsicTypeKind.Div, + Floor: IntrinsicTypeKind.Floor, + Ceil: IntrinsicTypeKind.Ceil, + Round: IntrinsicTypeKind.Round, })); const SymbolLinks = class implements SymbolLinks { @@ -2011,6 +2033,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var indexedAccessTypes = new Map(); var templateLiteralTypes = new Map(); var stringMappingTypes = new Map(); + var CalculationTypes = new Map(); var substitutionTypes = new Map(); var subtypeReductionCache = new Map(); var decoratorContextOverrideTypeCache = new Map(); @@ -6430,6 +6453,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const typeNode = typeToTypeNodeHelper((type as StringMappingType).type, context); return symbolToTypeNode((type as StringMappingType).symbol, context, SymbolFlags.Type, [typeNode]); } + if (type.flags & TypeFlags.Calculation) { + return symbolToTypeNode( + (type as CalculationType).symbol, + context, + SymbolFlags.Type, + (type as CalculationType).types.map(type => typeToTypeNodeHelper(type, context)), + ); + } if (type.flags & TypeFlags.IndexedAccess) { const objectTypeNode = typeToTypeNodeHelper((type as IndexedAccessType).objectType, context); const indexTypeNode = typeToTypeNodeHelper((type as IndexedAccessType).indexType, context); @@ -14611,7 +14642,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getBaseConstraintOfType(type: Type): Type | undefined { - if (type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.UnionOrIntersection | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) || isGenericTupleType(type)) { + if (type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.UnionOrIntersection | TypeFlags.TemplateLiteral | TypeFlags.StringMapping | TypeFlags.Calculation) || isGenericTupleType(type)) { const constraint = getResolvedBaseConstraint(type as InstantiableType | UnionOrIntersectionType); return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; } @@ -14722,7 +14753,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (t.flags & TypeFlags.StringMapping) { const constraint = getBaseConstraint((t as StringMappingType).type); - return constraint && constraint !== (t as StringMappingType).type ? getStringMappingType((t as StringMappingType).symbol, constraint) : stringType; + return constraint && constraint !== (t as StringMappingType).type ? getIntrinsicMappingType((t as StringMappingType).symbol, constraint) : stringType; + } + if (t.flags & TypeFlags.Calculation) { + const types = (t as CalculationType).types; + const constraints = mapDefined(types, getBaseConstraint); + return constraints.length === types.length + ? constraints.length === 1 + ? getIntrinsicMappingType((t as CalculationType).symbol, constraints[0]) + : getIntrinsicMappingType2((t as CalculationType).symbol, constraints[0], constraints[1]) + : numberType; } if (t.flags & TypeFlags.IndexedAccess) { if (isMappedTypeGenericIndexedAccess(t)) { @@ -16294,10 +16334,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getTypeAliasInstantiation(symbol: Symbol, typeArguments: readonly Type[] | undefined, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): Type { const type = getDeclaredTypeOfSymbol(symbol); - if (type === intrinsicMarkerType) { + if (type === intrinsicMarkerType && typeArguments) { const typeKind = intrinsicTypeKinds.get(symbol.escapedName as string); - if (typeKind !== undefined && typeArguments && typeArguments.length === 1) { - return typeKind === IntrinsicTypeKind.NoInfer ? getNoInferType(typeArguments[0]) : getStringMappingType(symbol, typeArguments[0]); + if (typeKind !== undefined && typeArguments.length === 1) { + return typeKind === IntrinsicTypeKind.NoInfer ? getNoInferType(typeArguments[0]) : getIntrinsicMappingType(symbol, typeArguments[0]); + } + if (typeKind !== undefined && typeArguments.length === 2) { + return getIntrinsicMappingType2(symbol, typeArguments[0], typeArguments[1]); } } const links = getSymbolLinks(symbol); @@ -17438,7 +17481,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const t = types[i]; const flags = t.flags; const remove = flags & (TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) && includes & TypeFlags.String || - flags & TypeFlags.NumberLiteral && includes & TypeFlags.Number || + flags & (TypeFlags.NumberLiteral | TypeFlags.Calculation) && includes & TypeFlags.Number || flags & TypeFlags.BigIntLiteral && includes & TypeFlags.BigInt || flags & TypeFlags.UniqueESSymbol && includes & TypeFlags.ESSymbol || reduceVoidUndefined && flags & TypeFlags.Undefined && includes & TypeFlags.Void || @@ -18159,6 +18202,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { type.flags & TypeFlags.IndexedAccess ? isDistributive((type as IndexedAccessType).objectType) && isDistributive((type as IndexedAccessType).indexType) : type.flags & TypeFlags.Substitution ? isDistributive((type as SubstitutionType).baseType) && isDistributive((type as SubstitutionType).constraint) : type.flags & TypeFlags.StringMapping ? isDistributive((type as StringMappingType).type) : + type.flags & TypeFlags.Calculation ? isDistributive((type as CalculationType).types[0]) || ((type as CalculationType).types.length === 2 && isDistributive((type as CalculationType).types[1]!)) : false; } } @@ -18351,18 +18395,61 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return type; } - function getStringMappingType(symbol: Symbol, type: Type): Type { - return type.flags & (TypeFlags.Union | TypeFlags.Never) ? mapType(type, t => getStringMappingType(symbol, t)) : + function getIntrinsicMappingType(symbol: Symbol, type: Type): Type { + return type.flags & (TypeFlags.Union | TypeFlags.Never) ? mapType(type, t => getIntrinsicMappingType(symbol, t)) : type.flags & TypeFlags.StringLiteral ? getStringLiteralType(applyStringMapping(symbol, (type as StringLiteralType).value)) : + type.flags & TypeFlags.NumberLiteral ? getNumberLiteralType(applyNumericUnary(symbol, (type as NumberLiteralType).value)) : type.flags & TypeFlags.TemplateLiteral ? getTemplateLiteralType(...applyTemplateStringMapping(symbol, (type as TemplateLiteralType).texts, (type as TemplateLiteralType).types)) : // Mapping> === Mapping type.flags & TypeFlags.StringMapping && symbol === type.symbol ? type : + type.flags & TypeFlags.Calculation ? getCalculationTypeForGenericType(symbol, [type]) : + // Floor/Ceil/Round === T when T is any, number, or bigint + (intrinsicUnaryKinds.has(intrinsicTypeKinds.get(symbol.escapedName as string)!) && (type.flags & (TypeFlags.Any | TypeFlags.Number | TypeFlags.BigInt))) ? type : type.flags & (TypeFlags.Any | TypeFlags.String | TypeFlags.StringMapping) || isGenericIndexType(type) ? getStringMappingTypeForGenericType(symbol, type) : // This handles Mapping<`${number}`> and Mapping<`${bigint}`> isPatternLiteralPlaceholderType(type) ? getStringMappingTypeForGenericType(symbol, getTemplateLiteralType(["", ""], [type])) : type; } + // Currently the only 2-type intrinsics are Calculation types (i.e. numeric) + function getIntrinsicMappingType2(symbol: Symbol, type1: Type, type2: Type): Type { + return type1.flags & (TypeFlags.Union | TypeFlags.Never) ? mapType(type1, t => getIntrinsicMappingType2(symbol, t, type2)) : + isGenericIndexType(type1) || isGenericIndexType(type2) ? getCalculationTypeForGenericType(symbol, [type1, type2]) : + type2.flags & (TypeFlags.Union | TypeFlags.Never) ? mapType(type2, t => getIntrinsicMappingType2(symbol, type1, t)) : + // handle division by zero + intrinsicTypeKinds.get(symbol.escapedName as string) === IntrinsicTypeKind.Div && type2.flags & TypeFlags.NumberLiteral && (type2 as NumberLiteralType).value === 0 ? neverType : + type1.flags & TypeFlags.NumberLiteral ? + type2.flags & TypeFlags.NumberLiteral ? getNumberLiteralType(applyNumericBinary(symbol, (type1 as NumberLiteralType).value, (type2 as NumberLiteralType).value)) : + type2 : + type1; + } + + function applyNumericUnary(symbol: Symbol, value: number): number { + switch (intrinsicTypeKinds.get(symbol.escapedName as string)) { + case IntrinsicTypeKind.Floor: + return Math.floor(value); + case IntrinsicTypeKind.Ceil: + return Math.ceil(value); + case IntrinsicTypeKind.Round: + return Math.round(value); + } + return value; + } + + function applyNumericBinary(symbol: Symbol, a: number, b: number): number { + switch (intrinsicTypeKinds.get(symbol.escapedName as string)) { + case IntrinsicTypeKind.Add: + return (a + b); + case IntrinsicTypeKind.Sub: + return (a - b); + case IntrinsicTypeKind.Mul: + return (a * b); + case IntrinsicTypeKind.Div: + return (a / b); + } + return a; + } + function applyStringMapping(symbol: Symbol, str: string) { switch (intrinsicTypeKinds.get(symbol.escapedName as string)) { case IntrinsicTypeKind.Uppercase: @@ -18380,13 +18467,33 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function applyTemplateStringMapping(symbol: Symbol, texts: readonly string[], types: readonly Type[]): [texts: readonly string[], types: readonly Type[]] { switch (intrinsicTypeKinds.get(symbol.escapedName as string)) { case IntrinsicTypeKind.Uppercase: - return [texts.map(t => t.toUpperCase()), types.map(t => getStringMappingType(symbol, t))]; + return [ + texts.map(t => t.toUpperCase()), + types.map(t => getIntrinsicMappingType(symbol, t)), + ]; case IntrinsicTypeKind.Lowercase: - return [texts.map(t => t.toLowerCase()), types.map(t => getStringMappingType(symbol, t))]; + return [ + texts.map(t => t.toLowerCase()), + types.map(t => getIntrinsicMappingType(symbol, t)), + ]; case IntrinsicTypeKind.Capitalize: - return [texts[0] === "" ? texts : [texts[0].charAt(0).toUpperCase() + texts[0].slice(1), ...texts.slice(1)], texts[0] === "" ? [getStringMappingType(symbol, types[0]), ...types.slice(1)] : types]; + return [ + texts[0] === "" ? + texts : + [texts[0].charAt(0).toUpperCase() + texts[0].slice(1), ...texts.slice(1)], + texts[0] === "" ? + [getIntrinsicMappingType(symbol, types[0]), ...types.slice(1)] : + types, + ]; case IntrinsicTypeKind.Uncapitalize: - return [texts[0] === "" ? texts : [texts[0].charAt(0).toLowerCase() + texts[0].slice(1), ...texts.slice(1)], texts[0] === "" ? [getStringMappingType(symbol, types[0]), ...types.slice(1)] : types]; + return [ + texts[0] === "" ? + texts : + [texts[0].charAt(0).toLowerCase() + texts[0].slice(1), ...texts.slice(1)], + texts[0] === "" ? + [getIntrinsicMappingType(symbol, types[0]), ...types.slice(1)] : + types, + ]; } return [texts, types]; } @@ -18400,6 +18507,22 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return result; } + function getCalculationTypeForGenericType(symbol: Symbol, types: [Type] | [Type, Type]): Type { + const id = `${getSymbolId(symbol)},${types.map(getTypeId).join(",")}`; + let result = CalculationTypes.get(id); + if (!result) { + CalculationTypes.set(id, result = createCalculationType(symbol, types)); + } + return result; + } + + function createCalculationType(symbol: Symbol, types: [Type] | [Type, Type]) { + const result = createType(TypeFlags.Calculation) as CalculationType; + result.symbol = symbol; + result.types = types; + return result; + } + function createStringMappingType(symbol: Symbol, type: Type) { const result = createTypeWithSymbol(TypeFlags.StringMapping, symbol) as StringMappingType; result.type = type; @@ -18689,8 +18812,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function isPatternLiteralType(type: Type) { // A pattern literal type is a template literal or a string mapping type that contains only // non-generic pattern literal placeholders. - return !!(type.flags & TypeFlags.TemplateLiteral) && every((type as TemplateLiteralType).types, isPatternLiteralPlaceholderType) || - !!(type.flags & TypeFlags.StringMapping) && isPatternLiteralPlaceholderType((type as StringMappingType).type); + return ( + !!(type.flags & TypeFlags.TemplateLiteral) && + every((type as TemplateLiteralType).types, isPatternLiteralPlaceholderType) || + !!(type.flags & TypeFlags.StringMapping) && + isPatternLiteralPlaceholderType((type as StringMappingType).type) + ); } function isGenericStringLikeType(type: Type) { @@ -19796,7 +19923,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function createTypeMapper(sources: readonly TypeParameter[], targets: readonly Type[] | undefined): TypeMapper { - return sources.length === 1 ? makeUnaryTypeMapper(sources[0], targets ? targets[0] : anyType) : makeArrayTypeMapper(sources, targets); + return sources.length === 1 ? + makeUnaryTypeMapper(sources[0], targets ? targets[0] : anyType) : + makeArrayTypeMapper(sources, targets); } function getMappedType(type: Type, mapper: TypeMapper): Type { @@ -20300,7 +20429,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return getTemplateLiteralType((type as TemplateLiteralType).texts, instantiateTypes((type as TemplateLiteralType).types, mapper)); } if (flags & TypeFlags.StringMapping) { - return getStringMappingType((type as StringMappingType).symbol, instantiateType((type as StringMappingType).type, mapper)); + return getIntrinsicMappingType((type as StringMappingType).symbol, instantiateType((type as StringMappingType).type, mapper)); + } + if (flags & TypeFlags.Calculation) { + const calculation = type as CalculationType; + if (calculation.types.length === 1) { + return getIntrinsicMappingType(calculation.symbol, instantiateType(calculation.types[0], mapper)); + } + return getIntrinsicMappingType2(calculation.symbol, instantiateType(calculation.types[0], mapper), instantiateType(calculation.types[1], mapper)); } if (flags & TypeFlags.IndexedAccess) { const newAliasSymbol = aliasSymbol || type.aliasSymbol; @@ -23103,6 +23239,27 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } } + else if (sourceFlags & TypeFlags.Calculation) { + const s = source as CalculationType; + if (targetFlags & TypeFlags.Calculation && s.symbol === (target as CalculationType).symbol) { + const t = target as CalculationType; + if (result = isRelatedTo(s.types[0], t.types[0], RecursionFlags.Both, reportErrors)) { + resetErrorInfo(saveErrorInfo); + return result; + } + if (s.types.length === 2 && t.types.length === 2 && (result = isRelatedTo(s.types[1], t.types[1], RecursionFlags.Both, reportErrors))) { + resetErrorInfo(saveErrorInfo); + return result; + } + } + else { + const constraint = getBaseConstraintOfType(source); + if (constraint && (result = isRelatedTo(constraint, target, RecursionFlags.Source, reportErrors))) { + resetErrorInfo(saveErrorInfo); + return result; + } + } + } else if (sourceFlags & TypeFlags.StringMapping) { if (targetFlags & TypeFlags.StringMapping) { if ((source as StringMappingType).symbol !== (target as StringMappingType).symbol) { @@ -24779,7 +24936,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getBaseTypeOfLiteralType(type: Type): Type { return type.flags & TypeFlags.EnumLike ? getBaseTypeOfEnumLikeType(type as LiteralType) : type.flags & (TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) ? stringType : - type.flags & TypeFlags.NumberLiteral ? numberType : + type.flags & (TypeFlags.NumberLiteral | TypeFlags.Calculation) ? numberType : type.flags & TypeFlags.BigIntLiteral ? bigintType : type.flags & TypeFlags.BooleanLiteral ? booleanType : type.flags & TypeFlags.Union ? getBaseTypeOfLiteralTypeUnion(type as UnionType) : @@ -25762,7 +25919,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { mappingStack.unshift(target.symbol); target = (target as StringMappingType).type; } - const mappedSource = reduceLeft(mappingStack, (memo, value) => getStringMappingType(value, memo), source); + const mappedSource = reduceLeft(mappingStack, (memo, value) => getIntrinsicMappingType(value, memo), source); return mappedSource === source && isMemberOfStringMapping(source, target); } return false; @@ -26090,6 +26247,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { inferFromTypes((source as StringMappingType).type, (target as StringMappingType).type); } } + else if (source.flags & TypeFlags.Calculation && target.flags & TypeFlags.Calculation) { + const sourceCalculation = source as CalculationType; + const targetCalculation = target as CalculationType; + if (sourceCalculation.symbol === targetCalculation.symbol) { + inferFromTypes(sourceCalculation.types[0], targetCalculation.types[0]); + if (sourceCalculation.types.length === 2 && targetCalculation.types.length === 2) { + inferFromTypes(sourceCalculation.types[1], targetCalculation.types[1]); + } + } + } else if (source.flags & TypeFlags.Substitution) { inferFromTypes((source as SubstitutionType).baseType, target); inferWithPriority(getSubstitutionIntersection(source as SubstitutionType), target, InferencePriority.SubstituteSource); // Make substitute inference at a lower priority @@ -26686,7 +26853,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function hasPrimitiveConstraint(type: TypeParameter): boolean { const constraint = getConstraintOfTypeParameter(type); - return !!constraint && maybeTypeOfKind(constraint.flags & TypeFlags.Conditional ? getDefaultConstraintOfConditionalType(constraint as ConditionalType) : constraint, TypeFlags.Primitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping); + return !!constraint && maybeTypeOfKind(constraint.flags & TypeFlags.Conditional ? getDefaultConstraintOfConditionalType(constraint as ConditionalType) : constraint, TypeFlags.Primitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping | TypeFlags.Calculation); } function isObjectLiteralType(type: Type) { @@ -27708,12 +27875,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function replacePrimitivesWithLiterals(typeWithPrimitives: Type, typeWithLiterals: Type) { if ( maybeTypeOfKind(typeWithPrimitives, TypeFlags.String | TypeFlags.TemplateLiteral | TypeFlags.Number | TypeFlags.BigInt) && - maybeTypeOfKind(typeWithLiterals, TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping | TypeFlags.NumberLiteral | TypeFlags.BigIntLiteral) + maybeTypeOfKind(typeWithLiterals, TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping | TypeFlags.Calculation | TypeFlags.NumberLiteral | TypeFlags.BigIntLiteral) ) { return mapType(typeWithPrimitives, t => t.flags & TypeFlags.String ? extractTypesOfKind(typeWithLiterals, TypeFlags.String | TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) : isPatternLiteralType(t) && !maybeTypeOfKind(typeWithLiterals, TypeFlags.String | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) ? extractTypesOfKind(typeWithLiterals, TypeFlags.StringLiteral) : - t.flags & TypeFlags.Number ? extractTypesOfKind(typeWithLiterals, TypeFlags.Number | TypeFlags.NumberLiteral) : + t.flags & TypeFlags.Number ? extractTypesOfKind(typeWithLiterals, TypeFlags.Number | TypeFlags.NumberLiteral | TypeFlags.Calculation) : t.flags & TypeFlags.BigInt ? extractTypesOfKind(typeWithLiterals, TypeFlags.BigInt | TypeFlags.BigIntLiteral) : t); } return typeWithPrimitives; @@ -34899,7 +35066,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { getContextualTypeForElementExpression(restType, i - index, argCount - index) || unknownType : getIndexedAccessType(restType, getNumberLiteralType(i - index), AccessFlags.Contextual); const argType = checkExpressionWithContextualType(arg, contextualType, context, checkMode); - const hasPrimitiveContextualType = inConstContext || maybeTypeOfKind(contextualType, TypeFlags.Primitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping); + const hasPrimitiveContextualType = inConstContext || maybeTypeOfKind(contextualType, TypeFlags.Primitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping | TypeFlags.Calculation); types.push(hasPrimitiveContextualType ? getRegularTypeOfLiteralType(argType) : getWidenedLiteralType(argType)); flags.push(ElementFlags.Required); } @@ -40129,7 +40296,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // If the contextual type is a literal of a particular primitive type, we consider this a // literal context for all literals of that primitive type. return !!(contextualType.flags & (TypeFlags.StringLiteral | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) && maybeTypeOfKind(candidateType, TypeFlags.StringLiteral) || - contextualType.flags & TypeFlags.NumberLiteral && maybeTypeOfKind(candidateType, TypeFlags.NumberLiteral) || + contextualType.flags & (TypeFlags.NumberLiteral | TypeFlags.Calculation) && maybeTypeOfKind(candidateType, TypeFlags.NumberLiteral) || contextualType.flags & TypeFlags.BigIntLiteral && maybeTypeOfKind(candidateType, TypeFlags.BigIntLiteral) || contextualType.flags & TypeFlags.BooleanLiteral && maybeTypeOfKind(candidateType, TypeFlags.BooleanLiteral) || contextualType.flags & TypeFlags.UniqueESSymbol && maybeTypeOfKind(candidateType, TypeFlags.UniqueESSymbol)); @@ -46292,7 +46459,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { checkExportsOnMergedDeclarations(node); checkTypeParameters(node.typeParameters); if (node.type.kind === SyntaxKind.IntrinsicKeyword) { - if (!intrinsicTypeKinds.has(node.name.escapedText as string) || length(node.typeParameters) !== 1) { + if (!intrinsicTypeKinds.has(node.name.escapedText as string) || !(length(node.typeParameters) === 1 || length(node.typeParameters) === 2)) { error(node.type, Diagnostics.The_intrinsic_keyword_can_only_be_used_to_declare_compiler_provided_intrinsic_types); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9df1b4a8e7f31..5666bbcd651fa 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6222,6 +6222,7 @@ export const enum TypeFlags { Reserved1 = 1 << 29, // Used by union/intersection type construction /** @internal */ Reserved2 = 1 << 30, // Used by union/intersection type construction + Calculation = 1 << 31, // Math type /** @internal */ AnyOrUnknown = Any | Unknown, @@ -6239,7 +6240,7 @@ export const enum TypeFlags { /** @internal */ Intrinsic = Any | Unknown | String | Number | BigInt | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive, StringLike = String | StringLiteral | TemplateLiteral | StringMapping, - NumberLike = Number | NumberLiteral | Enum, + NumberLike = Number | NumberLiteral | Enum | Calculation, BigIntLike = BigInt | BigIntLiteral, BooleanLike = Boolean | BooleanLiteral, EnumLike = Enum | EnumLiteral, @@ -6255,7 +6256,7 @@ export const enum TypeFlags { StructuredType = Object | Union | Intersection, TypeVariable = TypeParameter | IndexedAccess, InstantiableNonPrimitive = TypeVariable | Conditional | Substitution, - InstantiablePrimitive = Index | TemplateLiteral | StringMapping, + InstantiablePrimitive = Index | TemplateLiteral | StringMapping | Calculation, Instantiable = InstantiableNonPrimitive | InstantiablePrimitive, StructuredOrInstantiable = StructuredType | Instantiable, /** @internal */ @@ -6826,6 +6827,11 @@ export interface StringMappingType extends InstantiableType { type: Type; } +export interface CalculationType extends InstantiableType { + symbol: Symbol; + types: [Type] | [Type, Type]; +} + // Type parameter substitution (TypeFlags.Substitution) // Substitution types are created for type parameters or indexed access types that occur in the // true branch of a conditional type. For example, in 'T extends string ? Foo : Bar', the diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index f04ac4594f918..059cdcdc6594a 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1209,6 +1209,13 @@ export namespace Completion { typeEntry("Lowercase"), typeEntry("Capitalize"), typeEntry("Uncapitalize"), + typeEntry("Floor"), + typeEntry("Ceil"), + typeEntry("Round"), + typeEntry("Add"), + typeEntry("Subtract"), + typeEntry("Multiply"), + typeEntry("Divide"), typeEntry("NoInfer"), interfaceEntry("ThisType"), varEntry("ArrayBuffer"), diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 33bbb99147490..8bd794872cc1d 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1649,6 +1649,41 @@ type Capitalize = intrinsic; */ type Uncapitalize = intrinsic; +/** + * Convert a number literal type to an integer by flooring it + */ +type Floor = intrinsic; + +/** + * Convert a number literal type to an integer by ceiling it + */ +type Ceil = intrinsic; + +/** + * Convert a number literal type to integer by rounding it + */ +type Round = intrinsic; + +/** + * Add two literal numbers + */ +type Add = intrinsic; + +/** + * Subtract two literal numbers + */ +type Subtract = intrinsic; + +/** + * Multiply two literal numbers + */ +type Multiply = intrinsic; + +/** + * Divide two literal numbers + */ +type Divide = intrinsic; + /** * Marker for non-inference type position */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index e6dfbf9200437..d1bc4673cbb3d 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6549,13 +6549,14 @@ declare namespace ts { NonPrimitive = 67108864, TemplateLiteral = 134217728, StringMapping = 268435456, + Calculation = -2147483648, Literal = 2944, Unit = 109472, Freshable = 2976, StringOrNumberLiteral = 384, PossiblyFalsy = 117724, StringLike = 402653316, - NumberLike = 296, + NumberLike = -2147483352, BigIntLike = 2112, BooleanLike = 528, EnumLike = 1056, @@ -6565,10 +6566,10 @@ declare namespace ts { StructuredType = 3670016, TypeVariable = 8650752, InstantiableNonPrimitive = 58982400, - InstantiablePrimitive = 406847488, - Instantiable = 465829888, - StructuredOrInstantiable = 469499904, - Narrowable = 536624127, + InstantiablePrimitive = -1740636160, + Instantiable = -1681653760, + StructuredOrInstantiable = -1677983744, + Narrowable = -1610859521, } type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression; interface Type { @@ -6764,6 +6765,15 @@ declare namespace ts { symbol: Symbol; type: Type; } + interface CalculationType extends InstantiableType { + symbol: Symbol; + types: [ + Type, + ] | [ + Type, + Type, + ]; + } interface SubstitutionType extends InstantiableType { objectFlags: ObjectFlags; baseType: Type; diff --git a/tests/baselines/reference/intrinsicTypes.errors.txt b/tests/baselines/reference/intrinsicTypes.errors.txt index 32f7127864d62..902b0eda4d799 100644 --- a/tests/baselines/reference/intrinsicTypes.errors.txt +++ b/tests/baselines/reference/intrinsicTypes.errors.txt @@ -8,9 +8,28 @@ intrinsicTypes.ts(42,5): error TS2322: Type 'string' is not assignable to type ' intrinsicTypes.ts(43,5): error TS2322: Type 'Uppercase' is not assignable to type 'Uppercase'. Type 'T' is not assignable to type 'U'. 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'string'. +intrinsicTypes.ts(61,18): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(76,17): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(77,20): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(78,18): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(93,22): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(94,25): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(95,23): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(110,22): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(111,25): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(112,23): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(127,20): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(128,23): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(129,21): error TS2344: Type 'string' does not satisfy the constraint 'number'. +intrinsicTypes.ts(147,5): error TS2322: Type 'number' is not assignable to type 'Add'. +intrinsicTypes.ts(148,5): error TS2322: Type 'Multiply' is not assignable to type 'Add'. + Type 'number' is not assignable to type 'Add'. +intrinsicTypes.ts(149,5): error TS2322: Type 'number' is not assignable to type 'Multiply'. +intrinsicTypes.ts(150,5): error TS2322: Type 'Add' is not assignable to type 'Multiply'. + Type 'number' is not assignable to type 'Multiply'. -==== intrinsicTypes.ts (8 errors) ==== +==== intrinsicTypes.ts (25 errors) ==== type TU1 = Uppercase<'hello'>; // "HELLO" type TU2 = Uppercase<'foo' | 'bar'>; // "FOO" | "BAR" type TU3 = Uppercase; // Uppercase @@ -83,4 +102,147 @@ intrinsicTypes.ts(43,5): error TS2322: Type 'Uppercase' is not assignable to function foo4(x: Uppercase) { return foo3(x); } + + type TI1 = Floor<3.5>; // 3 + type TI2 = Floor<2.5 | 3.4>; // 2 | 3 + type TI3 = Floor; // number + type TI4 = Floor; // any + type TI5 = Floor; // never + type TI6 = Floor<'42'>; // Error + ~~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + + type TA1 = Add<4, 2>; // 6 + type TA2L = Add<4 | 5, 2>; // 6 | 7 + type TA2R = Add<4, 2 | 3>; // 6 | 7 + type TA2LR = Add<4 | 5, 2 | 3>; // 6 | 7 | 8 + type TA3L = Add; // number + type TA3R = Add<4, number>; // number + type TA3LR = Add; // number + type TA4L = Add; // any + type TA4R = Add<4, any>; // any + type TA4LR = Add; // any + type TA5L = Add; // never + type TA5R = Add<4, never>; // never + type TA5LR = Add; // never + type TA6L = Add<'4', 2>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + type TA6R = Add<4, '2'>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + type TA6LR = Add<'4', '2'>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + + type TS1 = Subtract<4, 2>; // 2 + type TS2L = Subtract<4 | 5, 2>; // 2 | 3 + type TS2R = Subtract<4, 2 | 3>; // 2 | 1 + type TS2LR = Subtract<4 | 5, 2 | 3>; // 2 | 1 | 3 + type TS3L = Subtract; // number + type TS3R = Subtract<4, number>; // number + type TS3LR = Subtract; // number + type TS4L = Subtract; // any + type TS4R = Subtract<4, any>; // any + type TS4LR = Subtract; // any + type TS5L = Subtract; // never + type TS5R = Subtract<4, never>; // never + type TS5LR = Subtract; // never + type TS6L = Subtract<'4', 2>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + type TS6R = Subtract<4, '2'>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + type TS6LR = Subtract<'4', '2'>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + + type TM1 = Multiply<4, 2>; // 8 + type TM2L = Multiply<4 | 5, 2>; // 8 | 10 + type TM2R = Multiply<4, 2 | 3>; // 8 | 12 + type TM2LR = Multiply<4 | 5, 2 | 3>; // 8 | 12 | 10 | 15 + type TM3L = Multiply; // number + type TM3R = Multiply<4, number>; // number + type TM3LR = Multiply; // number + type TM4L = Multiply; // any + type TM4R = Multiply<4, any>; // any + type TM4LR = Multiply; // any + type TM5L = Multiply; // never + type TM5R = Multiply<4, never>; // never + type TM5LR = Multiply; // never + type TM6L = Multiply<'4', 2>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + type TM6R = Multiply<4, '2'>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + type TM6LR = Multiply<'4', '2'>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + + type TD1 = Divide<4, 2>; // 2 + type TD2L = Divide<4 | 5, 2>; // 2 | 2.5 + type TD2R = Divide<4, 2 | 4>; // 2 | 1 + type TD2LR = Divide<4 | 5, 2 | 4>; // 2 | 1 | 2.5 | 1.25 + type TD3L = Divide; // number + type TD3R = Divide<4, number>; // number + type TD3LR = Divide; // number + type TD4L = Divide; // any + type TD4R = Divide<4, any>; // any + type TD4LR = Divide; // any + type TD5L = Divide; // never + type TD5R = Divide<4, never>; // never + type TD5LR = Divide; // never + type TD6L = Divide<'4', 2>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + type TD6R = Divide<4, '2'>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + type TD6LR = Divide<'4', '2'>; // Error + ~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + type TD7 = Divide<1, 0>; // never + + type TIX1 = Floor; + type TIX2 = TIX1<4.2>; // 4 + type TAX1 = Add; + type TAX2 = TAX1<4, 2>; // 6 + type TSX1 = Subtract; + type TSX2 = TSX1<4, 2>; // 6 + type TMX1 = Multiply; + type TMX2 = TMX1<4, 2>; // 8 + type TDX1 = Divide; + type TDX2 = TDX1<4, 2>; // 2 + type TAMX = Add<2, Multiply<5, 8>> // 42 + + function foo5(s: number, x: Add, y: Multiply) { + s = x; + s = y; + x = s; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'Add'. + x = y; // Error + ~ +!!! error TS2322: Type 'Multiply' is not assignable to type 'Add'. +!!! error TS2322: Type 'number' is not assignable to type 'Add'. + y = s; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'Multiply'. + y = x; // Error + ~ +!!! error TS2322: Type 'Add' is not assignable to type 'Multiply'. +!!! error TS2322: Type 'number' is not assignable to type 'Multiply'. + } + + function foo6(x: Add) { + let s: 3 | 4 = x; + } + + declare function foo7(x: Floor): T; + + function foo8(x: Floor) { + return foo7(x); + } \ No newline at end of file diff --git a/tests/baselines/reference/intrinsicTypes.js b/tests/baselines/reference/intrinsicTypes.js index 3cef1972903a6..b4c0503709dd5 100644 --- a/tests/baselines/reference/intrinsicTypes.js +++ b/tests/baselines/reference/intrinsicTypes.js @@ -55,6 +55,113 @@ declare function foo3(x: Uppercase): T; function foo4(x: Uppercase) { return foo3(x); } + +type TI1 = Floor<3.5>; // 3 +type TI2 = Floor<2.5 | 3.4>; // 2 | 3 +type TI3 = Floor; // number +type TI4 = Floor; // any +type TI5 = Floor; // never +type TI6 = Floor<'42'>; // Error + +type TA1 = Add<4, 2>; // 6 +type TA2L = Add<4 | 5, 2>; // 6 | 7 +type TA2R = Add<4, 2 | 3>; // 6 | 7 +type TA2LR = Add<4 | 5, 2 | 3>; // 6 | 7 | 8 +type TA3L = Add; // number +type TA3R = Add<4, number>; // number +type TA3LR = Add; // number +type TA4L = Add; // any +type TA4R = Add<4, any>; // any +type TA4LR = Add; // any +type TA5L = Add; // never +type TA5R = Add<4, never>; // never +type TA5LR = Add; // never +type TA6L = Add<'4', 2>; // Error +type TA6R = Add<4, '2'>; // Error +type TA6LR = Add<'4', '2'>; // Error + +type TS1 = Subtract<4, 2>; // 2 +type TS2L = Subtract<4 | 5, 2>; // 2 | 3 +type TS2R = Subtract<4, 2 | 3>; // 2 | 1 +type TS2LR = Subtract<4 | 5, 2 | 3>; // 2 | 1 | 3 +type TS3L = Subtract; // number +type TS3R = Subtract<4, number>; // number +type TS3LR = Subtract; // number +type TS4L = Subtract; // any +type TS4R = Subtract<4, any>; // any +type TS4LR = Subtract; // any +type TS5L = Subtract; // never +type TS5R = Subtract<4, never>; // never +type TS5LR = Subtract; // never +type TS6L = Subtract<'4', 2>; // Error +type TS6R = Subtract<4, '2'>; // Error +type TS6LR = Subtract<'4', '2'>; // Error + +type TM1 = Multiply<4, 2>; // 8 +type TM2L = Multiply<4 | 5, 2>; // 8 | 10 +type TM2R = Multiply<4, 2 | 3>; // 8 | 12 +type TM2LR = Multiply<4 | 5, 2 | 3>; // 8 | 12 | 10 | 15 +type TM3L = Multiply; // number +type TM3R = Multiply<4, number>; // number +type TM3LR = Multiply; // number +type TM4L = Multiply; // any +type TM4R = Multiply<4, any>; // any +type TM4LR = Multiply; // any +type TM5L = Multiply; // never +type TM5R = Multiply<4, never>; // never +type TM5LR = Multiply; // never +type TM6L = Multiply<'4', 2>; // Error +type TM6R = Multiply<4, '2'>; // Error +type TM6LR = Multiply<'4', '2'>; // Error + +type TD1 = Divide<4, 2>; // 2 +type TD2L = Divide<4 | 5, 2>; // 2 | 2.5 +type TD2R = Divide<4, 2 | 4>; // 2 | 1 +type TD2LR = Divide<4 | 5, 2 | 4>; // 2 | 1 | 2.5 | 1.25 +type TD3L = Divide; // number +type TD3R = Divide<4, number>; // number +type TD3LR = Divide; // number +type TD4L = Divide; // any +type TD4R = Divide<4, any>; // any +type TD4LR = Divide; // any +type TD5L = Divide; // never +type TD5R = Divide<4, never>; // never +type TD5LR = Divide; // never +type TD6L = Divide<'4', 2>; // Error +type TD6R = Divide<4, '2'>; // Error +type TD6LR = Divide<'4', '2'>; // Error +type TD7 = Divide<1, 0>; // never + +type TIX1 = Floor; +type TIX2 = TIX1<4.2>; // 4 +type TAX1 = Add; +type TAX2 = TAX1<4, 2>; // 6 +type TSX1 = Subtract; +type TSX2 = TSX1<4, 2>; // 6 +type TMX1 = Multiply; +type TMX2 = TMX1<4, 2>; // 8 +type TDX1 = Divide; +type TDX2 = TDX1<4, 2>; // 2 +type TAMX = Add<2, Multiply<5, 8>> // 42 + +function foo5(s: number, x: Add, y: Multiply) { + s = x; + s = y; + x = s; // Error + x = y; // Error + y = s; // Error + y = x; // Error +} + +function foo6(x: Add) { + let s: 3 | 4 = x; +} + +declare function foo7(x: Floor): T; + +function foo8(x: Floor) { + return foo7(x); +} //// [intrinsicTypes.js] @@ -73,6 +180,20 @@ function foo2(x) { function foo4(x) { return foo3(x); } +function foo5(s, x, y) { + s = x; + s = y; + x = s; // Error + x = y; // Error + y = s; // Error + y = x; // Error +} +function foo6(x) { + var s = x; +} +function foo8(x) { + return foo7(x); +} //// [intrinsicTypes.d.ts] @@ -110,3 +231,89 @@ declare function foo1(s: string, x: Uppercase, declare function foo2(x: Uppercase): void; declare function foo3(x: Uppercase): T; declare function foo4(x: Uppercase): U; +type TI1 = Floor<3.5>; +type TI2 = Floor<2.5 | 3.4>; +type TI3 = Floor; +type TI4 = Floor; +type TI5 = Floor; +type TI6 = Floor<'42'>; +type TA1 = Add<4, 2>; +type TA2L = Add<4 | 5, 2>; +type TA2R = Add<4, 2 | 3>; +type TA2LR = Add<4 | 5, 2 | 3>; +type TA3L = Add; +type TA3R = Add<4, number>; +type TA3LR = Add; +type TA4L = Add; +type TA4R = Add<4, any>; +type TA4LR = Add; +type TA5L = Add; +type TA5R = Add<4, never>; +type TA5LR = Add; +type TA6L = Add<'4', 2>; +type TA6R = Add<4, '2'>; +type TA6LR = Add<'4', '2'>; +type TS1 = Subtract<4, 2>; +type TS2L = Subtract<4 | 5, 2>; +type TS2R = Subtract<4, 2 | 3>; +type TS2LR = Subtract<4 | 5, 2 | 3>; +type TS3L = Subtract; +type TS3R = Subtract<4, number>; +type TS3LR = Subtract; +type TS4L = Subtract; +type TS4R = Subtract<4, any>; +type TS4LR = Subtract; +type TS5L = Subtract; +type TS5R = Subtract<4, never>; +type TS5LR = Subtract; +type TS6L = Subtract<'4', 2>; +type TS6R = Subtract<4, '2'>; +type TS6LR = Subtract<'4', '2'>; +type TM1 = Multiply<4, 2>; +type TM2L = Multiply<4 | 5, 2>; +type TM2R = Multiply<4, 2 | 3>; +type TM2LR = Multiply<4 | 5, 2 | 3>; +type TM3L = Multiply; +type TM3R = Multiply<4, number>; +type TM3LR = Multiply; +type TM4L = Multiply; +type TM4R = Multiply<4, any>; +type TM4LR = Multiply; +type TM5L = Multiply; +type TM5R = Multiply<4, never>; +type TM5LR = Multiply; +type TM6L = Multiply<'4', 2>; +type TM6R = Multiply<4, '2'>; +type TM6LR = Multiply<'4', '2'>; +type TD1 = Divide<4, 2>; +type TD2L = Divide<4 | 5, 2>; +type TD2R = Divide<4, 2 | 4>; +type TD2LR = Divide<4 | 5, 2 | 4>; +type TD3L = Divide; +type TD3R = Divide<4, number>; +type TD3LR = Divide; +type TD4L = Divide; +type TD4R = Divide<4, any>; +type TD4LR = Divide; +type TD5L = Divide; +type TD5R = Divide<4, never>; +type TD5LR = Divide; +type TD6L = Divide<'4', 2>; +type TD6R = Divide<4, '2'>; +type TD6LR = Divide<'4', '2'>; +type TD7 = Divide<1, 0>; +type TIX1 = Floor; +type TIX2 = TIX1<4.2>; +type TAX1 = Add; +type TAX2 = TAX1<4, 2>; +type TSX1 = Subtract; +type TSX2 = TSX1<4, 2>; +type TMX1 = Multiply; +type TMX2 = TMX1<4, 2>; +type TDX1 = Divide; +type TDX2 = TDX1<4, 2>; +type TAMX = Add<2, Multiply<5, 8>>; +declare function foo5(s: number, x: Add, y: Multiply): void; +declare function foo6(x: Add): void; +declare function foo7(x: Floor): T; +declare function foo8(x: Floor): U; diff --git a/tests/baselines/reference/intrinsicTypes.symbols b/tests/baselines/reference/intrinsicTypes.symbols index 57988a7acfba3..29f2cf396d811 100644 --- a/tests/baselines/reference/intrinsicTypes.symbols +++ b/tests/baselines/reference/intrinsicTypes.symbols @@ -196,3 +196,422 @@ function foo4(x: Uppercase) { >x : Symbol(x, Decl(intrinsicTypes.ts, 51, 32)) } +type TI1 = Floor<3.5>; // 3 +>TI1 : Symbol(TI1, Decl(intrinsicTypes.ts, 53, 1)) +>Floor : Symbol(Floor, Decl(lib.es5.d.ts, --, --)) + +type TI2 = Floor<2.5 | 3.4>; // 2 | 3 +>TI2 : Symbol(TI2, Decl(intrinsicTypes.ts, 55, 22)) +>Floor : Symbol(Floor, Decl(lib.es5.d.ts, --, --)) + +type TI3 = Floor; // number +>TI3 : Symbol(TI3, Decl(intrinsicTypes.ts, 56, 28)) +>Floor : Symbol(Floor, Decl(lib.es5.d.ts, --, --)) + +type TI4 = Floor; // any +>TI4 : Symbol(TI4, Decl(intrinsicTypes.ts, 57, 25)) +>Floor : Symbol(Floor, Decl(lib.es5.d.ts, --, --)) + +type TI5 = Floor; // never +>TI5 : Symbol(TI5, Decl(intrinsicTypes.ts, 58, 22)) +>Floor : Symbol(Floor, Decl(lib.es5.d.ts, --, --)) + +type TI6 = Floor<'42'>; // Error +>TI6 : Symbol(TI6, Decl(intrinsicTypes.ts, 59, 24)) +>Floor : Symbol(Floor, Decl(lib.es5.d.ts, --, --)) + +type TA1 = Add<4, 2>; // 6 +>TA1 : Symbol(TA1, Decl(intrinsicTypes.ts, 60, 23)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA2L = Add<4 | 5, 2>; // 6 | 7 +>TA2L : Symbol(TA2L, Decl(intrinsicTypes.ts, 62, 21)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA2R = Add<4, 2 | 3>; // 6 | 7 +>TA2R : Symbol(TA2R, Decl(intrinsicTypes.ts, 63, 26)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA2LR = Add<4 | 5, 2 | 3>; // 6 | 7 | 8 +>TA2LR : Symbol(TA2LR, Decl(intrinsicTypes.ts, 64, 26)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA3L = Add; // number +>TA3L : Symbol(TA3L, Decl(intrinsicTypes.ts, 65, 31)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA3R = Add<4, number>; // number +>TA3R : Symbol(TA3R, Decl(intrinsicTypes.ts, 66, 27)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA3LR = Add; // number +>TA3LR : Symbol(TA3LR, Decl(intrinsicTypes.ts, 67, 27)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA4L = Add; // any +>TA4L : Symbol(TA4L, Decl(intrinsicTypes.ts, 68, 33)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA4R = Add<4, any>; // any +>TA4R : Symbol(TA4R, Decl(intrinsicTypes.ts, 69, 24)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA4LR = Add; // any +>TA4LR : Symbol(TA4LR, Decl(intrinsicTypes.ts, 70, 24)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA5L = Add; // never +>TA5L : Symbol(TA5L, Decl(intrinsicTypes.ts, 71, 27)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA5R = Add<4, never>; // never +>TA5R : Symbol(TA5R, Decl(intrinsicTypes.ts, 72, 26)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA5LR = Add; // never +>TA5LR : Symbol(TA5LR, Decl(intrinsicTypes.ts, 73, 26)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA6L = Add<'4', 2>; // Error +>TA6L : Symbol(TA6L, Decl(intrinsicTypes.ts, 74, 31)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA6R = Add<4, '2'>; // Error +>TA6R : Symbol(TA6R, Decl(intrinsicTypes.ts, 75, 24)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TA6LR = Add<'4', '2'>; // Error +>TA6LR : Symbol(TA6LR, Decl(intrinsicTypes.ts, 76, 24)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) + +type TS1 = Subtract<4, 2>; // 2 +>TS1 : Symbol(TS1, Decl(intrinsicTypes.ts, 77, 27)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS2L = Subtract<4 | 5, 2>; // 2 | 3 +>TS2L : Symbol(TS2L, Decl(intrinsicTypes.ts, 79, 26)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS2R = Subtract<4, 2 | 3>; // 2 | 1 +>TS2R : Symbol(TS2R, Decl(intrinsicTypes.ts, 80, 31)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS2LR = Subtract<4 | 5, 2 | 3>; // 2 | 1 | 3 +>TS2LR : Symbol(TS2LR, Decl(intrinsicTypes.ts, 81, 31)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS3L = Subtract; // number +>TS3L : Symbol(TS3L, Decl(intrinsicTypes.ts, 82, 36)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS3R = Subtract<4, number>; // number +>TS3R : Symbol(TS3R, Decl(intrinsicTypes.ts, 83, 32)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS3LR = Subtract; // number +>TS3LR : Symbol(TS3LR, Decl(intrinsicTypes.ts, 84, 32)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS4L = Subtract; // any +>TS4L : Symbol(TS4L, Decl(intrinsicTypes.ts, 85, 38)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS4R = Subtract<4, any>; // any +>TS4R : Symbol(TS4R, Decl(intrinsicTypes.ts, 86, 29)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS4LR = Subtract; // any +>TS4LR : Symbol(TS4LR, Decl(intrinsicTypes.ts, 87, 29)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS5L = Subtract; // never +>TS5L : Symbol(TS5L, Decl(intrinsicTypes.ts, 88, 32)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS5R = Subtract<4, never>; // never +>TS5R : Symbol(TS5R, Decl(intrinsicTypes.ts, 89, 31)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS5LR = Subtract; // never +>TS5LR : Symbol(TS5LR, Decl(intrinsicTypes.ts, 90, 31)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS6L = Subtract<'4', 2>; // Error +>TS6L : Symbol(TS6L, Decl(intrinsicTypes.ts, 91, 36)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS6R = Subtract<4, '2'>; // Error +>TS6R : Symbol(TS6R, Decl(intrinsicTypes.ts, 92, 29)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TS6LR = Subtract<'4', '2'>; // Error +>TS6LR : Symbol(TS6LR, Decl(intrinsicTypes.ts, 93, 29)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) + +type TM1 = Multiply<4, 2>; // 8 +>TM1 : Symbol(TM1, Decl(intrinsicTypes.ts, 94, 32)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM2L = Multiply<4 | 5, 2>; // 8 | 10 +>TM2L : Symbol(TM2L, Decl(intrinsicTypes.ts, 96, 26)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM2R = Multiply<4, 2 | 3>; // 8 | 12 +>TM2R : Symbol(TM2R, Decl(intrinsicTypes.ts, 97, 31)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM2LR = Multiply<4 | 5, 2 | 3>; // 8 | 12 | 10 | 15 +>TM2LR : Symbol(TM2LR, Decl(intrinsicTypes.ts, 98, 31)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM3L = Multiply; // number +>TM3L : Symbol(TM3L, Decl(intrinsicTypes.ts, 99, 36)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM3R = Multiply<4, number>; // number +>TM3R : Symbol(TM3R, Decl(intrinsicTypes.ts, 100, 32)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM3LR = Multiply; // number +>TM3LR : Symbol(TM3LR, Decl(intrinsicTypes.ts, 101, 32)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM4L = Multiply; // any +>TM4L : Symbol(TM4L, Decl(intrinsicTypes.ts, 102, 38)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM4R = Multiply<4, any>; // any +>TM4R : Symbol(TM4R, Decl(intrinsicTypes.ts, 103, 29)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM4LR = Multiply; // any +>TM4LR : Symbol(TM4LR, Decl(intrinsicTypes.ts, 104, 29)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM5L = Multiply; // never +>TM5L : Symbol(TM5L, Decl(intrinsicTypes.ts, 105, 32)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM5R = Multiply<4, never>; // never +>TM5R : Symbol(TM5R, Decl(intrinsicTypes.ts, 106, 31)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM5LR = Multiply; // never +>TM5LR : Symbol(TM5LR, Decl(intrinsicTypes.ts, 107, 31)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM6L = Multiply<'4', 2>; // Error +>TM6L : Symbol(TM6L, Decl(intrinsicTypes.ts, 108, 36)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM6R = Multiply<4, '2'>; // Error +>TM6R : Symbol(TM6R, Decl(intrinsicTypes.ts, 109, 29)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TM6LR = Multiply<'4', '2'>; // Error +>TM6LR : Symbol(TM6LR, Decl(intrinsicTypes.ts, 110, 29)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +type TD1 = Divide<4, 2>; // 2 +>TD1 : Symbol(TD1, Decl(intrinsicTypes.ts, 111, 32)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD2L = Divide<4 | 5, 2>; // 2 | 2.5 +>TD2L : Symbol(TD2L, Decl(intrinsicTypes.ts, 113, 24)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD2R = Divide<4, 2 | 4>; // 2 | 1 +>TD2R : Symbol(TD2R, Decl(intrinsicTypes.ts, 114, 29)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD2LR = Divide<4 | 5, 2 | 4>; // 2 | 1 | 2.5 | 1.25 +>TD2LR : Symbol(TD2LR, Decl(intrinsicTypes.ts, 115, 29)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD3L = Divide; // number +>TD3L : Symbol(TD3L, Decl(intrinsicTypes.ts, 116, 34)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD3R = Divide<4, number>; // number +>TD3R : Symbol(TD3R, Decl(intrinsicTypes.ts, 117, 30)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD3LR = Divide; // number +>TD3LR : Symbol(TD3LR, Decl(intrinsicTypes.ts, 118, 30)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD4L = Divide; // any +>TD4L : Symbol(TD4L, Decl(intrinsicTypes.ts, 119, 36)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD4R = Divide<4, any>; // any +>TD4R : Symbol(TD4R, Decl(intrinsicTypes.ts, 120, 27)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD4LR = Divide; // any +>TD4LR : Symbol(TD4LR, Decl(intrinsicTypes.ts, 121, 27)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD5L = Divide; // never +>TD5L : Symbol(TD5L, Decl(intrinsicTypes.ts, 122, 30)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD5R = Divide<4, never>; // never +>TD5R : Symbol(TD5R, Decl(intrinsicTypes.ts, 123, 29)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD5LR = Divide; // never +>TD5LR : Symbol(TD5LR, Decl(intrinsicTypes.ts, 124, 29)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD6L = Divide<'4', 2>; // Error +>TD6L : Symbol(TD6L, Decl(intrinsicTypes.ts, 125, 34)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD6R = Divide<4, '2'>; // Error +>TD6R : Symbol(TD6R, Decl(intrinsicTypes.ts, 126, 27)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD6LR = Divide<'4', '2'>; // Error +>TD6LR : Symbol(TD6LR, Decl(intrinsicTypes.ts, 127, 27)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TD7 = Divide<1, 0>; // never +>TD7 : Symbol(TD7, Decl(intrinsicTypes.ts, 128, 30)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) + +type TIX1 = Floor; +>TIX1 : Symbol(TIX1, Decl(intrinsicTypes.ts, 129, 24)) +>S : Symbol(S, Decl(intrinsicTypes.ts, 131, 10)) +>Floor : Symbol(Floor, Decl(lib.es5.d.ts, --, --)) +>S : Symbol(S, Decl(intrinsicTypes.ts, 131, 10)) + +type TIX2 = TIX1<4.2>; // 4 +>TIX2 : Symbol(TIX2, Decl(intrinsicTypes.ts, 131, 39)) +>TIX1 : Symbol(TIX1, Decl(intrinsicTypes.ts, 129, 24)) + +type TAX1 = Add; +>TAX1 : Symbol(TAX1, Decl(intrinsicTypes.ts, 132, 22)) +>M : Symbol(M, Decl(intrinsicTypes.ts, 133, 10)) +>N : Symbol(N, Decl(intrinsicTypes.ts, 133, 27)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) +>M : Symbol(M, Decl(intrinsicTypes.ts, 133, 10)) +>N : Symbol(N, Decl(intrinsicTypes.ts, 133, 27)) + +type TAX2 = TAX1<4, 2>; // 6 +>TAX2 : Symbol(TAX2, Decl(intrinsicTypes.ts, 133, 58)) +>TAX1 : Symbol(TAX1, Decl(intrinsicTypes.ts, 132, 22)) + +type TSX1 = Subtract; +>TSX1 : Symbol(TSX1, Decl(intrinsicTypes.ts, 134, 23)) +>M : Symbol(M, Decl(intrinsicTypes.ts, 135, 10)) +>N : Symbol(N, Decl(intrinsicTypes.ts, 135, 27)) +>Subtract : Symbol(Subtract, Decl(lib.es5.d.ts, --, --)) +>M : Symbol(M, Decl(intrinsicTypes.ts, 135, 10)) +>N : Symbol(N, Decl(intrinsicTypes.ts, 135, 27)) + +type TSX2 = TSX1<4, 2>; // 6 +>TSX2 : Symbol(TSX2, Decl(intrinsicTypes.ts, 135, 63)) +>TSX1 : Symbol(TSX1, Decl(intrinsicTypes.ts, 134, 23)) + +type TMX1 = Multiply; +>TMX1 : Symbol(TMX1, Decl(intrinsicTypes.ts, 136, 23)) +>M : Symbol(M, Decl(intrinsicTypes.ts, 137, 10)) +>N : Symbol(N, Decl(intrinsicTypes.ts, 137, 27)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) +>M : Symbol(M, Decl(intrinsicTypes.ts, 137, 10)) +>N : Symbol(N, Decl(intrinsicTypes.ts, 137, 27)) + +type TMX2 = TMX1<4, 2>; // 8 +>TMX2 : Symbol(TMX2, Decl(intrinsicTypes.ts, 137, 63)) +>TMX1 : Symbol(TMX1, Decl(intrinsicTypes.ts, 136, 23)) + +type TDX1 = Divide; +>TDX1 : Symbol(TDX1, Decl(intrinsicTypes.ts, 138, 23)) +>M : Symbol(M, Decl(intrinsicTypes.ts, 139, 10)) +>N : Symbol(N, Decl(intrinsicTypes.ts, 139, 27)) +>Divide : Symbol(Divide, Decl(lib.es5.d.ts, --, --)) +>M : Symbol(M, Decl(intrinsicTypes.ts, 139, 10)) +>N : Symbol(N, Decl(intrinsicTypes.ts, 139, 27)) + +type TDX2 = TDX1<4, 2>; // 2 +>TDX2 : Symbol(TDX2, Decl(intrinsicTypes.ts, 139, 61)) +>TDX1 : Symbol(TDX1, Decl(intrinsicTypes.ts, 138, 23)) + +type TAMX = Add<2, Multiply<5, 8>> // 42 +>TAMX : Symbol(TAMX, Decl(intrinsicTypes.ts, 140, 23)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) + +function foo5(s: number, x: Add, y: Multiply) { +>foo5 : Symbol(foo5, Decl(intrinsicTypes.ts, 141, 34)) +>T : Symbol(T, Decl(intrinsicTypes.ts, 143, 14)) +>U : Symbol(U, Decl(intrinsicTypes.ts, 143, 31)) +>T : Symbol(T, Decl(intrinsicTypes.ts, 143, 14)) +>s : Symbol(s, Decl(intrinsicTypes.ts, 143, 45)) +>x : Symbol(x, Decl(intrinsicTypes.ts, 143, 55)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(intrinsicTypes.ts, 143, 14)) +>U : Symbol(U, Decl(intrinsicTypes.ts, 143, 31)) +>y : Symbol(y, Decl(intrinsicTypes.ts, 143, 69)) +>Multiply : Symbol(Multiply, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(intrinsicTypes.ts, 143, 14)) +>U : Symbol(U, Decl(intrinsicTypes.ts, 143, 31)) + + s = x; +>s : Symbol(s, Decl(intrinsicTypes.ts, 143, 45)) +>x : Symbol(x, Decl(intrinsicTypes.ts, 143, 55)) + + s = y; +>s : Symbol(s, Decl(intrinsicTypes.ts, 143, 45)) +>y : Symbol(y, Decl(intrinsicTypes.ts, 143, 69)) + + x = s; // Error +>x : Symbol(x, Decl(intrinsicTypes.ts, 143, 55)) +>s : Symbol(s, Decl(intrinsicTypes.ts, 143, 45)) + + x = y; // Error +>x : Symbol(x, Decl(intrinsicTypes.ts, 143, 55)) +>y : Symbol(y, Decl(intrinsicTypes.ts, 143, 69)) + + y = s; // Error +>y : Symbol(y, Decl(intrinsicTypes.ts, 143, 69)) +>s : Symbol(s, Decl(intrinsicTypes.ts, 143, 45)) + + y = x; // Error +>y : Symbol(y, Decl(intrinsicTypes.ts, 143, 69)) +>x : Symbol(x, Decl(intrinsicTypes.ts, 143, 55)) +} + +function foo6(x: Add) { +>foo6 : Symbol(foo6, Decl(intrinsicTypes.ts, 150, 1)) +>T : Symbol(T, Decl(intrinsicTypes.ts, 152, 14)) +>x : Symbol(x, Decl(intrinsicTypes.ts, 152, 31)) +>Add : Symbol(Add, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(intrinsicTypes.ts, 152, 14)) + + let s: 3 | 4 = x; +>s : Symbol(s, Decl(intrinsicTypes.ts, 153, 7)) +>x : Symbol(x, Decl(intrinsicTypes.ts, 152, 31)) +} + +declare function foo7(x: Floor): T; +>foo7 : Symbol(foo7, Decl(intrinsicTypes.ts, 154, 1)) +>T : Symbol(T, Decl(intrinsicTypes.ts, 156, 22)) +>x : Symbol(x, Decl(intrinsicTypes.ts, 156, 40)) +>Floor : Symbol(Floor, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(intrinsicTypes.ts, 156, 22)) +>T : Symbol(T, Decl(intrinsicTypes.ts, 156, 22)) + +function foo8(x: Floor) { +>foo8 : Symbol(foo8, Decl(intrinsicTypes.ts, 156, 56)) +>U : Symbol(U, Decl(intrinsicTypes.ts, 158, 14)) +>x : Symbol(x, Decl(intrinsicTypes.ts, 158, 32)) +>Floor : Symbol(Floor, Decl(lib.es5.d.ts, --, --)) +>U : Symbol(U, Decl(intrinsicTypes.ts, 158, 14)) + + return foo7(x); +>foo7 : Symbol(foo7, Decl(intrinsicTypes.ts, 154, 1)) +>x : Symbol(x, Decl(intrinsicTypes.ts, 158, 32)) +} + diff --git a/tests/baselines/reference/intrinsicTypes.types b/tests/baselines/reference/intrinsicTypes.types index 9d681b643e808..8f6b2d856fa6c 100644 --- a/tests/baselines/reference/intrinsicTypes.types +++ b/tests/baselines/reference/intrinsicTypes.types @@ -214,3 +214,424 @@ function foo4(x: Uppercase) { > : ^^^^^^^^^^^^ } +type TI1 = Floor<3.5>; // 3 +>TI1 : 3 +> : ^ + +type TI2 = Floor<2.5 | 3.4>; // 2 | 3 +>TI2 : 3 | 2 +> : ^^^^^ + +type TI3 = Floor; // number +>TI3 : number +> : ^^^^^^ + +type TI4 = Floor; // any +>TI4 : any +> : ^^^ + +type TI5 = Floor; // never +>TI5 : never +> : ^^^^^ + +type TI6 = Floor<'42'>; // Error +>TI6 : "42" +> : ^^^^ + +type TA1 = Add<4, 2>; // 6 +>TA1 : 6 +> : ^ + +type TA2L = Add<4 | 5, 2>; // 6 | 7 +>TA2L : 6 | 7 +> : ^^^^^ + +type TA2R = Add<4, 2 | 3>; // 6 | 7 +>TA2R : 6 | 7 +> : ^^^^^ + +type TA2LR = Add<4 | 5, 2 | 3>; // 6 | 7 | 8 +>TA2LR : 6 | 7 | 8 +> : ^^^^^^^^^ + +type TA3L = Add; // number +>TA3L : number +> : ^^^^^^ + +type TA3R = Add<4, number>; // number +>TA3R : number +> : ^^^^^^ + +type TA3LR = Add; // number +>TA3LR : number +> : ^^^^^^ + +type TA4L = Add; // any +>TA4L : any +> : ^^^ + +type TA4R = Add<4, any>; // any +>TA4R : any +> : ^^^ + +type TA4LR = Add; // any +>TA4LR : any +> : ^^^ + +type TA5L = Add; // never +>TA5L : never +> : ^^^^^ + +type TA5R = Add<4, never>; // never +>TA5R : never +> : ^^^^^ + +type TA5LR = Add; // never +>TA5LR : never +> : ^^^^^ + +type TA6L = Add<'4', 2>; // Error +>TA6L : "4" +> : ^^^ + +type TA6R = Add<4, '2'>; // Error +>TA6R : "2" +> : ^^^ + +type TA6LR = Add<'4', '2'>; // Error +>TA6LR : "4" +> : ^^^ + +type TS1 = Subtract<4, 2>; // 2 +>TS1 : 2 +> : ^ + +type TS2L = Subtract<4 | 5, 2>; // 2 | 3 +>TS2L : 3 | 2 +> : ^^^^^ + +type TS2R = Subtract<4, 2 | 3>; // 2 | 1 +>TS2R : 2 | 1 +> : ^^^^^ + +type TS2LR = Subtract<4 | 5, 2 | 3>; // 2 | 1 | 3 +>TS2LR : 3 | 2 | 1 +> : ^^^^^^^^^ + +type TS3L = Subtract; // number +>TS3L : number +> : ^^^^^^ + +type TS3R = Subtract<4, number>; // number +>TS3R : number +> : ^^^^^^ + +type TS3LR = Subtract; // number +>TS3LR : number +> : ^^^^^^ + +type TS4L = Subtract; // any +>TS4L : any +> : ^^^ + +type TS4R = Subtract<4, any>; // any +>TS4R : any +> : ^^^ + +type TS4LR = Subtract; // any +>TS4LR : any +> : ^^^ + +type TS5L = Subtract; // never +>TS5L : never +> : ^^^^^ + +type TS5R = Subtract<4, never>; // never +>TS5R : never +> : ^^^^^ + +type TS5LR = Subtract; // never +>TS5LR : never +> : ^^^^^ + +type TS6L = Subtract<'4', 2>; // Error +>TS6L : "4" +> : ^^^ + +type TS6R = Subtract<4, '2'>; // Error +>TS6R : "2" +> : ^^^ + +type TS6LR = Subtract<'4', '2'>; // Error +>TS6LR : "4" +> : ^^^ + +type TM1 = Multiply<4, 2>; // 8 +>TM1 : 8 +> : ^ + +type TM2L = Multiply<4 | 5, 2>; // 8 | 10 +>TM2L : 8 | 10 +> : ^^^^^^ + +type TM2R = Multiply<4, 2 | 3>; // 8 | 12 +>TM2R : 8 | 12 +> : ^^^^^^ + +type TM2LR = Multiply<4 | 5, 2 | 3>; // 8 | 12 | 10 | 15 +>TM2LR : 8 | 10 | 12 | 15 +> : ^^^^^^^^^^^^^^^^ + +type TM3L = Multiply; // number +>TM3L : number +> : ^^^^^^ + +type TM3R = Multiply<4, number>; // number +>TM3R : number +> : ^^^^^^ + +type TM3LR = Multiply; // number +>TM3LR : number +> : ^^^^^^ + +type TM4L = Multiply; // any +>TM4L : any +> : ^^^ + +type TM4R = Multiply<4, any>; // any +>TM4R : any +> : ^^^ + +type TM4LR = Multiply; // any +>TM4LR : any +> : ^^^ + +type TM5L = Multiply; // never +>TM5L : never +> : ^^^^^ + +type TM5R = Multiply<4, never>; // never +>TM5R : never +> : ^^^^^ + +type TM5LR = Multiply; // never +>TM5LR : never +> : ^^^^^ + +type TM6L = Multiply<'4', 2>; // Error +>TM6L : "4" +> : ^^^ + +type TM6R = Multiply<4, '2'>; // Error +>TM6R : "2" +> : ^^^ + +type TM6LR = Multiply<'4', '2'>; // Error +>TM6LR : "4" +> : ^^^ + +type TD1 = Divide<4, 2>; // 2 +>TD1 : 2 +> : ^ + +type TD2L = Divide<4 | 5, 2>; // 2 | 2.5 +>TD2L : 2.5 | 2 +> : ^^^^^^^ + +type TD2R = Divide<4, 2 | 4>; // 2 | 1 +>TD2R : 2 | 1 +> : ^^^^^ + +type TD2LR = Divide<4 | 5, 2 | 4>; // 2 | 1 | 2.5 | 1.25 +>TD2LR : 2.5 | 2 | 1 | 1.25 +> : ^^^^^^^^^^^^^^^^^^ + +type TD3L = Divide; // number +>TD3L : number +> : ^^^^^^ + +type TD3R = Divide<4, number>; // number +>TD3R : number +> : ^^^^^^ + +type TD3LR = Divide; // number +>TD3LR : number +> : ^^^^^^ + +type TD4L = Divide; // any +>TD4L : any +> : ^^^ + +type TD4R = Divide<4, any>; // any +>TD4R : any +> : ^^^ + +type TD4LR = Divide; // any +>TD4LR : any +> : ^^^ + +type TD5L = Divide; // never +>TD5L : never +> : ^^^^^ + +type TD5R = Divide<4, never>; // never +>TD5R : never +> : ^^^^^ + +type TD5LR = Divide; // never +>TD5LR : never +> : ^^^^^ + +type TD6L = Divide<'4', 2>; // Error +>TD6L : "4" +> : ^^^ + +type TD6R = Divide<4, '2'>; // Error +>TD6R : "2" +> : ^^^ + +type TD6LR = Divide<'4', '2'>; // Error +>TD6LR : "4" +> : ^^^ + +type TD7 = Divide<1, 0>; // never +>TD7 : never +> : ^^^^^ + +type TIX1 = Floor; +>TIX1 : Floor +> : ^^^^^^^^ + +type TIX2 = TIX1<4.2>; // 4 +>TIX2 : 4 +> : ^ + +type TAX1 = Add; +>TAX1 : Add +> : ^^^^^^^^^ + +type TAX2 = TAX1<4, 2>; // 6 +>TAX2 : 6 +> : ^ + +type TSX1 = Subtract; +>TSX1 : Subtract +> : ^^^^^^^^^^^^^^ + +type TSX2 = TSX1<4, 2>; // 6 +>TSX2 : 2 +> : ^ + +type TMX1 = Multiply; +>TMX1 : Multiply +> : ^^^^^^^^^^^^^^ + +type TMX2 = TMX1<4, 2>; // 8 +>TMX2 : 8 +> : ^ + +type TDX1 = Divide; +>TDX1 : Divide +> : ^^^^^^^^^^^^ + +type TDX2 = TDX1<4, 2>; // 2 +>TDX2 : 2 +> : ^ + +type TAMX = Add<2, Multiply<5, 8>> // 42 +>TAMX : 42 +> : ^^ + +function foo5(s: number, x: Add, y: Multiply) { +>foo5 : (s: number, x: Add, y: Multiply) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>s : number +> : ^^^^^^ +>x : Add +> : ^^^^^^^^^ +>y : Multiply +> : ^^^^^^^^^^^^^^ + + s = x; +>s = x : Add +> : ^^^^^^^^^ +>s : number +> : ^^^^^^ +>x : Add +> : ^^^^^^^^^ + + s = y; +>s = y : Multiply +> : ^^^^^^^^^^^^^^ +>s : number +> : ^^^^^^ +>y : Multiply +> : ^^^^^^^^^^^^^^ + + x = s; // Error +>x = s : number +> : ^^^^^^ +>x : Add +> : ^^^^^^^^^ +>s : number +> : ^^^^^^ + + x = y; // Error +>x = y : Multiply +> : ^^^^^^^^^^^^^^ +>x : Add +> : ^^^^^^^^^ +>y : Multiply +> : ^^^^^^^^^^^^^^ + + y = s; // Error +>y = s : number +> : ^^^^^^ +>y : Multiply +> : ^^^^^^^^^^^^^^ +>s : number +> : ^^^^^^ + + y = x; // Error +>y = x : Add +> : ^^^^^^^^^ +>y : Multiply +> : ^^^^^^^^^^^^^^ +>x : Add +> : ^^^^^^^^^ +} + +function foo6(x: Add) { +>foo6 : (x: Add) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^ +>x : Add +> : ^^^^^^^^^ + + let s: 3 | 4 = x; +>s : 3 | 4 +> : ^^^^^ +>x : 3 | 4 +> : ^^^^^ +} + +declare function foo7(x: Floor): T; +>foo7 : (x: Floor) => T +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>x : Floor +> : ^^^^^^^^ + +function foo8(x: Floor) { +>foo8 : (x: Floor) => U +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^^ +>x : Floor +> : ^^^^^^^^ + + return foo7(x); +>foo7(x) : U +> : ^ +>foo7 : (x: Floor) => T +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>x : Floor +> : ^^^^^^^^ +} + diff --git a/tests/baselines/reference/recursiveConditionalCrash4.errors.txt b/tests/baselines/reference/recursiveConditionalCrash4.errors.txt index 9a55044866b75..aec49bc395b41 100644 --- a/tests/baselines/reference/recursiveConditionalCrash4.errors.txt +++ b/tests/baselines/reference/recursiveConditionalCrash4.errors.txt @@ -1,7 +1,7 @@ recursiveConditionalCrash4.ts(7,16): error TS2503: Cannot find namespace 'StrIter'. recursiveConditionalCrash4.ts(8,5): error TS2503: Cannot find namespace 'StrIter'. -recursiveConditionalCrash4.ts(9,25): error TS2304: Cannot find name 'Add'. -recursiveConditionalCrash4.ts(9,37): error TS2503: Cannot find namespace 'StrIter'. +recursiveConditionalCrash4.ts(9,25): error TS2304: Cannot find name 'AddTuple'. +recursiveConditionalCrash4.ts(9,42): error TS2503: Cannot find namespace 'StrIter'. recursiveConditionalCrash4.ts(10,7): error TS2589: Type instantiation is excessively deep and possibly infinite. recursiveConditionalCrash4.ts(10,31): error TS2503: Cannot find namespace 'StrIter'. recursiveConditionalCrash4.ts(16,7): error TS2589: Type instantiation is excessively deep and possibly infinite. @@ -20,10 +20,10 @@ recursiveConditionalCrash4.ts(16,7): error TS2589: Type instantiation is excessi ? StrIter.CutAt extends `${infer $Rest}` ~~~~~~~ !!! error TS2503: Cannot find namespace 'StrIter'. - ? LengthDown<$Rest, Add>, It> - ~~~ -!!! error TS2304: Cannot find name 'Add'. - ~~~~~~~ + ? LengthDown<$Rest, AddTuple>, It> + ~~~~~~~~ +!!! error TS2304: Cannot find name 'AddTuple'. + ~~~~~~~ !!! error TS2503: Cannot find namespace 'StrIter'. : LengthDown> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/recursiveConditionalCrash4.symbols b/tests/baselines/reference/recursiveConditionalCrash4.symbols index 9319d18bd8c4e..6f2d4f88f2309 100644 --- a/tests/baselines/reference/recursiveConditionalCrash4.symbols +++ b/tests/baselines/reference/recursiveConditionalCrash4.symbols @@ -27,10 +27,10 @@ type LengthDown< >It : Symbol(It, Decl(recursiveConditionalCrash4.ts, 4, 33)) >$Rest : Symbol($Rest, Decl(recursiveConditionalCrash4.ts, 7, 43)) - ? LengthDown<$Rest, Add>, It> + ? LengthDown<$Rest, AddTuple>, It> >LengthDown : Symbol(LengthDown, Decl(recursiveConditionalCrash4.ts, 0, 0)) >$Rest : Symbol($Rest, Decl(recursiveConditionalCrash4.ts, 7, 43)) ->Add : Symbol(Add) +>AddTuple : Symbol(AddTuple) >Length : Symbol(Length, Decl(recursiveConditionalCrash4.ts, 3, 21)) >StrIter : Symbol(StrIter) >Value : Symbol(StrIter.Value) diff --git a/tests/baselines/reference/recursiveConditionalCrash4.types b/tests/baselines/reference/recursiveConditionalCrash4.types index 309edb17dc063..c3e55b2ced5b2 100644 --- a/tests/baselines/reference/recursiveConditionalCrash4.types +++ b/tests/baselines/reference/recursiveConditionalCrash4.types @@ -18,7 +18,7 @@ type LengthDown< >StrIter : any > : ^^^ - ? LengthDown<$Rest, Add>, It> + ? LengthDown<$Rest, AddTuple>, It> >StrIter : any > : ^^^ diff --git a/tests/baselines/reference/recursiveConditionalTypes.errors.txt b/tests/baselines/reference/recursiveConditionalTypes.errors.txt index ed33be5060593..a793c0be0830f 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.errors.txt +++ b/tests/baselines/reference/recursiveConditionalTypes.errors.txt @@ -206,10 +206,10 @@ recursiveConditionalTypes.ts(169,5): error TS2322: Type 'number' is not assignab type NTuple = Tup['length'] extends N ? Tup : NTuple; - type Add = + type AddTuples = [...NTuple, ...NTuple]['length']; - let five: Add<2, 3>; + let five: AddTuples<2, 3>; // Repro from #46316 diff --git a/tests/baselines/reference/recursiveConditionalTypes.js b/tests/baselines/reference/recursiveConditionalTypes.js index b99ddac1ee003..dd82729f6408e 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.js +++ b/tests/baselines/reference/recursiveConditionalTypes.js @@ -145,10 +145,10 @@ type TP2 = ParseManyWhitespace2<" foo">; type NTuple = Tup['length'] extends N ? Tup : NTuple; -type Add = +type AddTuples = [...NTuple, ...NTuple]['length']; -let five: Add<2, 3>; +let five: AddTuples<2, 3>; // Repro from #46316 @@ -283,11 +283,11 @@ type ParseManyWhitespace2 = S extends ` ${infer R0}` ? Helper< type Helper = T extends ParseSuccess ? ParseSuccess : null; type TP2 = ParseManyWhitespace2<" foo">; type NTuple = Tup['length'] extends N ? Tup : NTuple; -type Add = [ +type AddTuples = [ ...NTuple, ...NTuple ]['length']; -declare let five: Add<2, 3>; +declare let five: AddTuples<2, 3>; type _PrependNextNum> = A['length'] extends infer T ? [T, ...A] extends [...infer X] ? X : never : never; type _Enumerate, N extends number> = N extends A['length'] ? A : _Enumerate<_PrependNextNum, N> & number; type Enumerate = number extends N ? number : _Enumerate<[], N> extends (infer E)[] ? E : never; diff --git a/tests/baselines/reference/recursiveConditionalTypes.symbols b/tests/baselines/reference/recursiveConditionalTypes.symbols index 8bf1bf55f2154..d3d0c208024ad 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.symbols +++ b/tests/baselines/reference/recursiveConditionalTypes.symbols @@ -548,25 +548,25 @@ type NTuple = >N : Symbol(N, Decl(recursiveConditionalTypes.ts, 141, 12)) >Tup : Symbol(Tup, Decl(recursiveConditionalTypes.ts, 141, 29)) -type Add = ->Add : Symbol(Add, Decl(recursiveConditionalTypes.ts, 142, 65)) ->A : Symbol(A, Decl(recursiveConditionalTypes.ts, 144, 9)) ->B : Symbol(B, Decl(recursiveConditionalTypes.ts, 144, 26)) +type AddTuples = +>AddTuples : Symbol(AddTuples, Decl(recursiveConditionalTypes.ts, 142, 65)) +>A : Symbol(A, Decl(recursiveConditionalTypes.ts, 144, 15)) +>B : Symbol(B, Decl(recursiveConditionalTypes.ts, 144, 32)) [...NTuple, ...NTuple]['length']; >NTuple : Symbol(NTuple, Decl(recursiveConditionalTypes.ts, 137, 40)) ->A : Symbol(A, Decl(recursiveConditionalTypes.ts, 144, 9)) +>A : Symbol(A, Decl(recursiveConditionalTypes.ts, 144, 15)) >NTuple : Symbol(NTuple, Decl(recursiveConditionalTypes.ts, 137, 40)) ->B : Symbol(B, Decl(recursiveConditionalTypes.ts, 144, 26)) +>B : Symbol(B, Decl(recursiveConditionalTypes.ts, 144, 32)) -let five: Add<2, 3>; +let five: AddTuples<2, 3>; >five : Symbol(five, Decl(recursiveConditionalTypes.ts, 147, 3)) ->Add : Symbol(Add, Decl(recursiveConditionalTypes.ts, 142, 65)) +>AddTuples : Symbol(AddTuples, Decl(recursiveConditionalTypes.ts, 142, 65)) // Repro from #46316 type _PrependNextNum> = A['length'] extends infer T ->_PrependNextNum : Symbol(_PrependNextNum, Decl(recursiveConditionalTypes.ts, 147, 20)) +>_PrependNextNum : Symbol(_PrependNextNum, Decl(recursiveConditionalTypes.ts, 147, 26)) >A : Symbol(A, Decl(recursiveConditionalTypes.ts, 151, 21)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) >A : Symbol(A, Decl(recursiveConditionalTypes.ts, 151, 21)) @@ -596,7 +596,7 @@ type _Enumerate, N extends number> = N extends A['lengt : _Enumerate<_PrependNextNum, N> & number; >_Enumerate : Symbol(_Enumerate, Decl(recursiveConditionalTypes.ts, 155, 12)) ->_PrependNextNum : Symbol(_PrependNextNum, Decl(recursiveConditionalTypes.ts, 147, 20)) +>_PrependNextNum : Symbol(_PrependNextNum, Decl(recursiveConditionalTypes.ts, 147, 26)) >A : Symbol(A, Decl(recursiveConditionalTypes.ts, 157, 16)) >N : Symbol(N, Decl(recursiveConditionalTypes.ts, 157, 41)) diff --git a/tests/baselines/reference/recursiveConditionalTypes.types b/tests/baselines/reference/recursiveConditionalTypes.types index f09267bc93ba3..c9fea22d0bb7a 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.types +++ b/tests/baselines/reference/recursiveConditionalTypes.types @@ -509,13 +509,13 @@ type NTuple = Tup['length'] extends N ? Tup : NTuple; -type Add = ->Add : Add -> : ^^^^^^^^^ +type AddTuples = +>AddTuples : AddTuples +> : ^^^^^^^^^^^^^^^ [...NTuple, ...NTuple]['length']; -let five: Add<2, 3>; +let five: AddTuples<2, 3>; >five : 5 > : ^ diff --git a/tests/baselines/reference/tsserver/fourslashServer/autoImportProvider_namespaceSameNameAsIntrinsic.js b/tests/baselines/reference/tsserver/fourslashServer/autoImportProvider_namespaceSameNameAsIntrinsic.js index ffb5faecf4d5f..159fc43a14c22 100644 --- a/tests/baselines/reference/tsserver/fourslashServer/autoImportProvider_namespaceSameNameAsIntrinsic.js +++ b/tests/baselines/reference/tsserver/fourslashServer/autoImportProvider_namespaceSameNameAsIntrinsic.js @@ -368,6 +368,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "", "sortText": "11" }, + { + "name": "Add", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "any", "kind": "keyword", @@ -470,6 +476,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Ceil", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "ClassAccessorDecoratorContext", "kind": "interface", @@ -584,6 +596,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Divide", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "Error", "kind": "var", @@ -650,6 +668,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Floor", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "Function", "kind": "var", @@ -776,6 +800,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Multiply", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "never", "kind": "keyword", @@ -1004,6 +1034,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Round", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "string", "kind": "keyword", @@ -1022,6 +1058,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Subtract", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "symbol", "kind": "keyword", diff --git a/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_revertUpdatedFile.js b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_revertUpdatedFile.js index 3386cebb96943..87c655aa292e3 100644 --- a/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_revertUpdatedFile.js +++ b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_revertUpdatedFile.js @@ -385,6 +385,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "", "sortText": "11" }, + { + "name": "Add", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "any", "kind": "keyword", @@ -487,6 +493,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Ceil", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "ClassAccessorDecoratorContext", "kind": "interface", @@ -607,6 +619,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Divide", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "Error", "kind": "var", @@ -673,6 +691,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Floor", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "Function", "kind": "var", @@ -799,6 +823,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Multiply", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "never", "kind": "keyword", @@ -1027,6 +1057,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Round", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "string", "kind": "keyword", @@ -1045,6 +1081,12 @@ Info seq [hh:mm:ss:mss] response: "kindModifiers": "declare", "sortText": "15" }, + { + "name": "Subtract", + "kind": "type", + "kindModifiers": "declare", + "sortText": "15" + }, { "name": "symbol", "kind": "keyword", diff --git a/tests/cases/compiler/recursiveConditionalCrash4.ts b/tests/cases/compiler/recursiveConditionalCrash4.ts index 9cbe16188edf9..26b88c280153c 100644 --- a/tests/cases/compiler/recursiveConditionalCrash4.ts +++ b/tests/cases/compiler/recursiveConditionalCrash4.ts @@ -9,7 +9,7 @@ type LengthDown< It > = It extends StrIter.Iterator ? StrIter.CutAt extends `${infer $Rest}` - ? LengthDown<$Rest, Add>, It> + ? LengthDown<$Rest, AddTuple>, It> : LengthDown> : Length; diff --git a/tests/cases/compiler/recursiveConditionalTypes.ts b/tests/cases/compiler/recursiveConditionalTypes.ts index 44a28b863e483..3be66b97f2211 100644 --- a/tests/cases/compiler/recursiveConditionalTypes.ts +++ b/tests/cases/compiler/recursiveConditionalTypes.ts @@ -146,10 +146,10 @@ type TP2 = ParseManyWhitespace2<" foo">; type NTuple = Tup['length'] extends N ? Tup : NTuple; -type Add = +type AddTuples = [...NTuple, ...NTuple]['length']; -let five: Add<2, 3>; +let five: AddTuples<2, 3>; // Repro from #46316 diff --git a/tests/cases/conformance/types/typeAliases/intrinsicTypes.ts b/tests/cases/conformance/types/typeAliases/intrinsicTypes.ts index 118595e53cd73..be83604244748 100644 --- a/tests/cases/conformance/types/typeAliases/intrinsicTypes.ts +++ b/tests/cases/conformance/types/typeAliases/intrinsicTypes.ts @@ -55,3 +55,110 @@ declare function foo3(x: Uppercase): T; function foo4(x: Uppercase) { return foo3(x); } + +type TI1 = Floor<3.5>; // 3 +type TI2 = Floor<2.5 | 3.4>; // 2 | 3 +type TI3 = Floor; // number +type TI4 = Floor; // any +type TI5 = Floor; // never +type TI6 = Floor<'42'>; // Error + +type TA1 = Add<4, 2>; // 6 +type TA2L = Add<4 | 5, 2>; // 6 | 7 +type TA2R = Add<4, 2 | 3>; // 6 | 7 +type TA2LR = Add<4 | 5, 2 | 3>; // 6 | 7 | 8 +type TA3L = Add; // number +type TA3R = Add<4, number>; // number +type TA3LR = Add; // number +type TA4L = Add; // any +type TA4R = Add<4, any>; // any +type TA4LR = Add; // any +type TA5L = Add; // never +type TA5R = Add<4, never>; // never +type TA5LR = Add; // never +type TA6L = Add<'4', 2>; // Error +type TA6R = Add<4, '2'>; // Error +type TA6LR = Add<'4', '2'>; // Error + +type TS1 = Subtract<4, 2>; // 2 +type TS2L = Subtract<4 | 5, 2>; // 2 | 3 +type TS2R = Subtract<4, 2 | 3>; // 2 | 1 +type TS2LR = Subtract<4 | 5, 2 | 3>; // 2 | 1 | 3 +type TS3L = Subtract; // number +type TS3R = Subtract<4, number>; // number +type TS3LR = Subtract; // number +type TS4L = Subtract; // any +type TS4R = Subtract<4, any>; // any +type TS4LR = Subtract; // any +type TS5L = Subtract; // never +type TS5R = Subtract<4, never>; // never +type TS5LR = Subtract; // never +type TS6L = Subtract<'4', 2>; // Error +type TS6R = Subtract<4, '2'>; // Error +type TS6LR = Subtract<'4', '2'>; // Error + +type TM1 = Multiply<4, 2>; // 8 +type TM2L = Multiply<4 | 5, 2>; // 8 | 10 +type TM2R = Multiply<4, 2 | 3>; // 8 | 12 +type TM2LR = Multiply<4 | 5, 2 | 3>; // 8 | 12 | 10 | 15 +type TM3L = Multiply; // number +type TM3R = Multiply<4, number>; // number +type TM3LR = Multiply; // number +type TM4L = Multiply; // any +type TM4R = Multiply<4, any>; // any +type TM4LR = Multiply; // any +type TM5L = Multiply; // never +type TM5R = Multiply<4, never>; // never +type TM5LR = Multiply; // never +type TM6L = Multiply<'4', 2>; // Error +type TM6R = Multiply<4, '2'>; // Error +type TM6LR = Multiply<'4', '2'>; // Error + +type TD1 = Divide<4, 2>; // 2 +type TD2L = Divide<4 | 5, 2>; // 2 | 2.5 +type TD2R = Divide<4, 2 | 4>; // 2 | 1 +type TD2LR = Divide<4 | 5, 2 | 4>; // 2 | 1 | 2.5 | 1.25 +type TD3L = Divide; // number +type TD3R = Divide<4, number>; // number +type TD3LR = Divide; // number +type TD4L = Divide; // any +type TD4R = Divide<4, any>; // any +type TD4LR = Divide; // any +type TD5L = Divide; // never +type TD5R = Divide<4, never>; // never +type TD5LR = Divide; // never +type TD6L = Divide<'4', 2>; // Error +type TD6R = Divide<4, '2'>; // Error +type TD6LR = Divide<'4', '2'>; // Error +type TD7 = Divide<1, 0>; // never + +type TIX1 = Floor; +type TIX2 = TIX1<4.2>; // 4 +type TAX1 = Add; +type TAX2 = TAX1<4, 2>; // 6 +type TSX1 = Subtract; +type TSX2 = TSX1<4, 2>; // 6 +type TMX1 = Multiply; +type TMX2 = TMX1<4, 2>; // 8 +type TDX1 = Divide; +type TDX2 = TDX1<4, 2>; // 2 +type TAMX = Add<2, Multiply<5, 8>> // 42 + +function foo5(s: number, x: Add, y: Multiply) { + s = x; + s = y; + x = s; // Error + x = y; // Error + y = s; // Error + y = x; // Error +} + +function foo6(x: Add) { + let s: 3 | 4 = x; +} + +declare function foo7(x: Floor): T; + +function foo8(x: Floor) { + return foo7(x); +}