diff --git a/lib/tsc.js b/lib/tsc.js index 53dd3801d1d49..d98c47c3d7d30 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -18,7 +18,7 @@ and limitations under the License. // src/compiler/corePublic.ts var versionMajorMinor = "5.3"; -var version = "5.3.2"; +var version = "5.3.3"; // src/compiler/core.ts var emptyArray = []; @@ -3678,7 +3678,7 @@ var TypeFlags = /* @__PURE__ */ ((TypeFlags2) => { TypeFlags2[TypeFlags2["InstantiablePrimitive"] = 406847488] = "InstantiablePrimitive"; TypeFlags2[TypeFlags2["Instantiable"] = 465829888] = "Instantiable"; TypeFlags2[TypeFlags2["StructuredOrInstantiable"] = 469499904] = "StructuredOrInstantiable"; - TypeFlags2[TypeFlags2["ObjectFlagsType"] = 138117121] = "ObjectFlagsType"; + TypeFlags2[TypeFlags2["ObjectFlagsType"] = 3899393] = "ObjectFlagsType"; TypeFlags2[TypeFlags2["Simplifiable"] = 25165824] = "Simplifiable"; TypeFlags2[TypeFlags2["Singleton"] = 67358815] = "Singleton"; TypeFlags2[TypeFlags2["Narrowable"] = 536624127] = "Narrowable"; @@ -15971,7 +15971,7 @@ function getClassLikeDeclarationOfSymbol(symbol) { return (_a = symbol.declarations) == null ? void 0 : _a.find(isClassLike); } function getObjectFlags(type) { - return type.flags & 138117121 /* ObjectFlagsType */ ? type.objectFlags : 0; + return type.flags & 3899393 /* ObjectFlagsType */ ? type.objectFlags : 0; } function isUMDExportSymbol(symbol) { return !!symbol && !!symbol.declarations && !!symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]); @@ -56944,7 +56944,7 @@ function createTypeChecker(host) { } } function removeStringLiteralsMatchedByTemplateLiterals(types) { - const templates = filter(types, (t) => !!(t.flags & 134217728 /* TemplateLiteral */) && isPatternLiteralType(t) && t.types.every((t2) => !(t2.flags & 2097152 /* Intersection */) || !areIntersectedTypesAvoidingPrimitiveReduction(t2.types))); + const templates = filter(types, (t) => !!(t.flags & 134217728 /* TemplateLiteral */) && isPatternLiteralType(t)); if (templates.length) { let i = types.length; while (i > 0) { @@ -57344,19 +57344,14 @@ function createTypeChecker(host) { function getConstituentCountOfTypes(types) { return reduceLeft(types, (n, t) => n + getConstituentCount(t), 0); } - function areIntersectedTypesAvoidingPrimitiveReduction(types, primitiveFlags = 4 /* String */ | 8 /* Number */ | 64 /* BigInt */) { - if (types.length !== 2) { - return false; - } - const [t1, t2] = types; - return !!(t1.flags & primitiveFlags) && t2 === emptyTypeLiteralType || !!(t2.flags & primitiveFlags) && t1 === emptyTypeLiteralType; - } function getTypeFromIntersectionTypeNode(node) { const links = getNodeLinks(node); if (!links.resolvedType) { const aliasSymbol = getAliasSymbolForTypeNode(node); const types = map(node.types, getTypeFromTypeNode); - const noSupertypeReduction = areIntersectedTypesAvoidingPrimitiveReduction(types); + const emptyIndex = types.length === 2 ? types.indexOf(emptyTypeLiteralType) : -1; + const t = emptyIndex >= 0 ? types[1 - emptyIndex] : unknownType; + const noSupertypeReduction = !!(t.flags & (4 /* String */ | 8 /* Number */ | 64 /* BigInt */) || t.flags & 134217728 /* TemplateLiteral */ && isPatternLiteralType(t)); links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction); } return links.resolvedType; @@ -57568,11 +57563,6 @@ function createTypeChecker(host) { } function createTemplateLiteralType(texts, types) { const type = createType(134217728 /* TemplateLiteral */); - type.objectFlags = getPropagatingFlagsOfTypes( - types, - /*excludeKinds*/ - 98304 /* Nullable */ - ); type.texts = texts; type.types = types; return type; @@ -57867,7 +57857,15 @@ function createTypeChecker(host) { } function isPatternLiteralPlaceholderType(type) { if (type.flags & 2097152 /* Intersection */) { - return !isGenericType(type) && some(type.types, (t) => !!(t.flags & (2944 /* Literal */ | 98304 /* Nullable */)) || isPatternLiteralPlaceholderType(t)); + let seenPlaceholder = false; + for (const t of type.types) { + if (t.flags & (2944 /* Literal */ | 98304 /* Nullable */) || isPatternLiteralPlaceholderType(t)) { + seenPlaceholder = true; + } else if (!(t.flags & 524288 /* Object */)) { + return false; + } + } + return seenPlaceholder; } return !!(type.flags & (1 /* Any */ | 4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) || isPatternLiteralType(type); } @@ -57884,7 +57882,7 @@ function createTypeChecker(host) { return !!(getGenericObjectFlags(type) & 8388608 /* IsGenericIndexType */); } function getGenericObjectFlags(type) { - if (type.flags & (3145728 /* UnionOrIntersection */ | 134217728 /* TemplateLiteral */)) { + if (type.flags & 3145728 /* UnionOrIntersection */) { if (!(type.objectFlags & 2097152 /* IsGenericTypeComputed */)) { type.objectFlags |= 2097152 /* IsGenericTypeComputed */ | reduceLeft(type.types, (flags, t) => flags | getGenericObjectFlags(t), 0); } @@ -57896,7 +57894,7 @@ function createTypeChecker(host) { } return type.objectFlags & 12582912 /* IsGenericType */; } - return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 4194304 /* IsGenericObjectType */ : 0) | (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 8388608 /* IsGenericIndexType */ : 0); + return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 4194304 /* IsGenericObjectType */ : 0) | (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 8388608 /* IsGenericIndexType */ : 0); } function getSimplifiedType(type, writing) { return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) : type; @@ -58922,7 +58920,7 @@ function createTypeChecker(host) { result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) : target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) : instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments); target.instantiations.set(id, result); const resultObjectFlags = getObjectFlags(result); - if (result.flags & 138117121 /* ObjectFlagsType */ && !(resultObjectFlags & 524288 /* CouldContainTypeVariablesComputed */)) { + if (result.flags & 3899393 /* ObjectFlagsType */ && !(resultObjectFlags & 524288 /* CouldContainTypeVariablesComputed */)) { const resultCouldContainTypeVariables = some(typeArguments, couldContainTypeVariables); if (!(getObjectFlags(result) & 524288 /* CouldContainTypeVariablesComputed */)) { if (resultObjectFlags & (32 /* Mapped */ | 16 /* Anonymous */ | 4 /* Reference */)) { @@ -63636,8 +63634,8 @@ function createTypeChecker(host) { if (objectFlags & 524288 /* CouldContainTypeVariablesComputed */) { return !!(objectFlags & 1048576 /* CouldContainTypeVariables */); } - const result = !!(type.flags & 465829888 /* Instantiable */ || type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || some(getTypeArguments(type), couldContainTypeVariables)) || objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations || objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 4194304 /* ObjectRestType */ | 8388608 /* InstantiationExpressionType */)) || type.flags & (3145728 /* UnionOrIntersection */ | 134217728 /* TemplateLiteral */) && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && some(type.types, couldContainTypeVariables)); - if (type.flags & 138117121 /* ObjectFlagsType */) { + const result = !!(type.flags & 465829888 /* Instantiable */ || type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || some(getTypeArguments(type), couldContainTypeVariables)) || objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations || objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 4194304 /* ObjectRestType */ | 8388608 /* InstantiationExpressionType */)) || type.flags & 3145728 /* UnionOrIntersection */ && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && some(type.types, couldContainTypeVariables)); + if (type.flags & 3899393 /* ObjectFlagsType */) { type.objectFlags |= 524288 /* CouldContainTypeVariablesComputed */ | (result ? 1048576 /* CouldContainTypeVariables */ : 0); } return result; @@ -66155,10 +66153,10 @@ function createTypeChecker(host) { if (isMatchingConstructorReference(right)) { return narrowTypeByConstructor(type, operator, left, assumeTrue); } - if (isBooleanLiteral(right)) { + if (isBooleanLiteral(right) && !isAccessExpression(left)) { return narrowTypeByBooleanComparison(type, left, right, operator, assumeTrue); } - if (isBooleanLiteral(left)) { + if (isBooleanLiteral(left) && !isAccessExpression(right)) { return narrowTypeByBooleanComparison(type, right, left, operator, assumeTrue); } break; diff --git a/lib/tsserver.js b/lib/tsserver.js index c2d335d8cf2fc..dd6b532de2dd7 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -2328,7 +2328,7 @@ module.exports = __toCommonJS(server_exports); // src/compiler/corePublic.ts var versionMajorMinor = "5.3"; -var version = "5.3.2"; +var version = "5.3.3"; var Comparison = /* @__PURE__ */ ((Comparison3) => { Comparison3[Comparison3["LessThan"] = -1] = "LessThan"; Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo"; @@ -6670,7 +6670,7 @@ var TypeFlags = /* @__PURE__ */ ((TypeFlags2) => { TypeFlags2[TypeFlags2["InstantiablePrimitive"] = 406847488] = "InstantiablePrimitive"; TypeFlags2[TypeFlags2["Instantiable"] = 465829888] = "Instantiable"; TypeFlags2[TypeFlags2["StructuredOrInstantiable"] = 469499904] = "StructuredOrInstantiable"; - TypeFlags2[TypeFlags2["ObjectFlagsType"] = 138117121] = "ObjectFlagsType"; + TypeFlags2[TypeFlags2["ObjectFlagsType"] = 3899393] = "ObjectFlagsType"; TypeFlags2[TypeFlags2["Simplifiable"] = 25165824] = "Simplifiable"; TypeFlags2[TypeFlags2["Singleton"] = 67358815] = "Singleton"; TypeFlags2[TypeFlags2["Narrowable"] = 536624127] = "Narrowable"; @@ -20036,7 +20036,7 @@ function getClassLikeDeclarationOfSymbol(symbol) { return (_a = symbol.declarations) == null ? void 0 : _a.find(isClassLike); } function getObjectFlags(type) { - return type.flags & 138117121 /* ObjectFlagsType */ ? type.objectFlags : 0; + return type.flags & 3899393 /* ObjectFlagsType */ ? type.objectFlags : 0; } function forSomeAncestorDirectory(directory, callback) { return !!forEachAncestorDirectory(directory, (d) => callback(d) ? true : void 0); @@ -61648,7 +61648,7 @@ function createTypeChecker(host) { } } function removeStringLiteralsMatchedByTemplateLiterals(types) { - const templates = filter(types, (t) => !!(t.flags & 134217728 /* TemplateLiteral */) && isPatternLiteralType(t) && t.types.every((t2) => !(t2.flags & 2097152 /* Intersection */) || !areIntersectedTypesAvoidingPrimitiveReduction(t2.types))); + const templates = filter(types, (t) => !!(t.flags & 134217728 /* TemplateLiteral */) && isPatternLiteralType(t)); if (templates.length) { let i = types.length; while (i > 0) { @@ -62048,19 +62048,14 @@ function createTypeChecker(host) { function getConstituentCountOfTypes(types) { return reduceLeft(types, (n, t) => n + getConstituentCount(t), 0); } - function areIntersectedTypesAvoidingPrimitiveReduction(types, primitiveFlags = 4 /* String */ | 8 /* Number */ | 64 /* BigInt */) { - if (types.length !== 2) { - return false; - } - const [t1, t2] = types; - return !!(t1.flags & primitiveFlags) && t2 === emptyTypeLiteralType || !!(t2.flags & primitiveFlags) && t1 === emptyTypeLiteralType; - } function getTypeFromIntersectionTypeNode(node) { const links = getNodeLinks(node); if (!links.resolvedType) { const aliasSymbol = getAliasSymbolForTypeNode(node); const types = map(node.types, getTypeFromTypeNode); - const noSupertypeReduction = areIntersectedTypesAvoidingPrimitiveReduction(types); + const emptyIndex = types.length === 2 ? types.indexOf(emptyTypeLiteralType) : -1; + const t = emptyIndex >= 0 ? types[1 - emptyIndex] : unknownType; + const noSupertypeReduction = !!(t.flags & (4 /* String */ | 8 /* Number */ | 64 /* BigInt */) || t.flags & 134217728 /* TemplateLiteral */ && isPatternLiteralType(t)); links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction); } return links.resolvedType; @@ -62272,11 +62267,6 @@ function createTypeChecker(host) { } function createTemplateLiteralType(texts, types) { const type = createType(134217728 /* TemplateLiteral */); - type.objectFlags = getPropagatingFlagsOfTypes( - types, - /*excludeKinds*/ - 98304 /* Nullable */ - ); type.texts = texts; type.types = types; return type; @@ -62571,7 +62561,15 @@ function createTypeChecker(host) { } function isPatternLiteralPlaceholderType(type) { if (type.flags & 2097152 /* Intersection */) { - return !isGenericType(type) && some(type.types, (t) => !!(t.flags & (2944 /* Literal */ | 98304 /* Nullable */)) || isPatternLiteralPlaceholderType(t)); + let seenPlaceholder = false; + for (const t of type.types) { + if (t.flags & (2944 /* Literal */ | 98304 /* Nullable */) || isPatternLiteralPlaceholderType(t)) { + seenPlaceholder = true; + } else if (!(t.flags & 524288 /* Object */)) { + return false; + } + } + return seenPlaceholder; } return !!(type.flags & (1 /* Any */ | 4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) || isPatternLiteralType(type); } @@ -62588,7 +62586,7 @@ function createTypeChecker(host) { return !!(getGenericObjectFlags(type) & 8388608 /* IsGenericIndexType */); } function getGenericObjectFlags(type) { - if (type.flags & (3145728 /* UnionOrIntersection */ | 134217728 /* TemplateLiteral */)) { + if (type.flags & 3145728 /* UnionOrIntersection */) { if (!(type.objectFlags & 2097152 /* IsGenericTypeComputed */)) { type.objectFlags |= 2097152 /* IsGenericTypeComputed */ | reduceLeft(type.types, (flags, t) => flags | getGenericObjectFlags(t), 0); } @@ -62600,7 +62598,7 @@ function createTypeChecker(host) { } return type.objectFlags & 12582912 /* IsGenericType */; } - return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 4194304 /* IsGenericObjectType */ : 0) | (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 8388608 /* IsGenericIndexType */ : 0); + return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 4194304 /* IsGenericObjectType */ : 0) | (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 8388608 /* IsGenericIndexType */ : 0); } function getSimplifiedType(type, writing) { return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) : type; @@ -63626,7 +63624,7 @@ function createTypeChecker(host) { result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) : target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) : instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments); target.instantiations.set(id, result); const resultObjectFlags = getObjectFlags(result); - if (result.flags & 138117121 /* ObjectFlagsType */ && !(resultObjectFlags & 524288 /* CouldContainTypeVariablesComputed */)) { + if (result.flags & 3899393 /* ObjectFlagsType */ && !(resultObjectFlags & 524288 /* CouldContainTypeVariablesComputed */)) { const resultCouldContainTypeVariables = some(typeArguments, couldContainTypeVariables); if (!(getObjectFlags(result) & 524288 /* CouldContainTypeVariablesComputed */)) { if (resultObjectFlags & (32 /* Mapped */ | 16 /* Anonymous */ | 4 /* Reference */)) { @@ -68340,8 +68338,8 @@ function createTypeChecker(host) { if (objectFlags & 524288 /* CouldContainTypeVariablesComputed */) { return !!(objectFlags & 1048576 /* CouldContainTypeVariables */); } - const result = !!(type.flags & 465829888 /* Instantiable */ || type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || some(getTypeArguments(type), couldContainTypeVariables)) || objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations || objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 4194304 /* ObjectRestType */ | 8388608 /* InstantiationExpressionType */)) || type.flags & (3145728 /* UnionOrIntersection */ | 134217728 /* TemplateLiteral */) && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && some(type.types, couldContainTypeVariables)); - if (type.flags & 138117121 /* ObjectFlagsType */) { + const result = !!(type.flags & 465829888 /* Instantiable */ || type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || some(getTypeArguments(type), couldContainTypeVariables)) || objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations || objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 4194304 /* ObjectRestType */ | 8388608 /* InstantiationExpressionType */)) || type.flags & 3145728 /* UnionOrIntersection */ && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && some(type.types, couldContainTypeVariables)); + if (type.flags & 3899393 /* ObjectFlagsType */) { type.objectFlags |= 524288 /* CouldContainTypeVariablesComputed */ | (result ? 1048576 /* CouldContainTypeVariables */ : 0); } return result; @@ -70859,10 +70857,10 @@ function createTypeChecker(host) { if (isMatchingConstructorReference(right)) { return narrowTypeByConstructor(type, operator, left, assumeTrue); } - if (isBooleanLiteral(right)) { + if (isBooleanLiteral(right) && !isAccessExpression(left)) { return narrowTypeByBooleanComparison(type, left, right, operator, assumeTrue); } - if (isBooleanLiteral(left)) { + if (isBooleanLiteral(left) && !isAccessExpression(right)) { return narrowTypeByBooleanComparison(type, right, left, operator, assumeTrue); } break; @@ -137311,7 +137309,7 @@ function transpileModule(input, transpileOptions) { options ), setExternalModuleIndicator: getSetExternalModuleIndicator(options), - jsDocParsingMode: 1 /* ParseNone */ + jsDocParsingMode: transpileOptions.jsDocParsingMode ?? 0 /* ParseAll */ } ); if (transpileOptions.moduleName) { diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 5ee1d5258cb01..754fc50cdd483 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -6018,9 +6018,11 @@ declare namespace ts { /** @deprecated */ type AssertionKey = ImportAttributeName; /** @deprecated */ - type AssertEntry = ImportAttribute; + interface AssertEntry extends ImportAttribute { + } /** @deprecated */ - type AssertClause = ImportAttributes; + interface AssertClause extends ImportAttributes { + } type ImportAttributeName = Identifier | StringLiteral; interface ImportAttribute extends Node { readonly kind: SyntaxKind.ImportAttribute; @@ -10416,7 +10418,7 @@ declare namespace ts { installPackage?(options: InstallPackageOptions): Promise; writeFile?(fileName: string, content: string): void; getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined; - jsDocParsingMode?: JSDocParsingMode; + jsDocParsingMode?: JSDocParsingMode | undefined; } type WithMetadata = T & { metadata?: unknown; @@ -11612,6 +11614,7 @@ declare namespace ts { moduleName?: string; renamedDependencies?: MapLike; transformers?: CustomTransformers; + jsDocParsingMode?: JSDocParsingMode; } interface TranspileOutput { outputText: string; diff --git a/lib/typescript.js b/lib/typescript.js index 86ab90b9fb71b..fe732a6cb2627 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -35,7 +35,7 @@ var ts = (() => { "src/compiler/corePublic.ts"() { "use strict"; versionMajorMinor = "5.3"; - version = "5.3.2"; + version = "5.3.3"; Comparison = /* @__PURE__ */ ((Comparison3) => { Comparison3[Comparison3["LessThan"] = -1] = "LessThan"; Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo"; @@ -4435,7 +4435,7 @@ ${lanes.join("\n")} TypeFlags2[TypeFlags2["InstantiablePrimitive"] = 406847488] = "InstantiablePrimitive"; TypeFlags2[TypeFlags2["Instantiable"] = 465829888] = "Instantiable"; TypeFlags2[TypeFlags2["StructuredOrInstantiable"] = 469499904] = "StructuredOrInstantiable"; - TypeFlags2[TypeFlags2["ObjectFlagsType"] = 138117121] = "ObjectFlagsType"; + TypeFlags2[TypeFlags2["ObjectFlagsType"] = 3899393] = "ObjectFlagsType"; TypeFlags2[TypeFlags2["Simplifiable"] = 25165824] = "Simplifiable"; TypeFlags2[TypeFlags2["Singleton"] = 67358815] = "Singleton"; TypeFlags2[TypeFlags2["Narrowable"] = 536624127] = "Narrowable"; @@ -17337,7 +17337,7 @@ ${lanes.join("\n")} return (_a = symbol.declarations) == null ? void 0 : _a.find(isClassLike); } function getObjectFlags(type) { - return type.flags & 138117121 /* ObjectFlagsType */ ? type.objectFlags : 0; + return type.flags & 3899393 /* ObjectFlagsType */ ? type.objectFlags : 0; } function forSomeAncestorDirectory(directory, callback) { return !!forEachAncestorDirectory(directory, (d) => callback(d) ? true : void 0); @@ -59415,7 +59415,7 @@ ${lanes.join("\n")} } } function removeStringLiteralsMatchedByTemplateLiterals(types) { - const templates = filter(types, (t) => !!(t.flags & 134217728 /* TemplateLiteral */) && isPatternLiteralType(t) && t.types.every((t2) => !(t2.flags & 2097152 /* Intersection */) || !areIntersectedTypesAvoidingPrimitiveReduction(t2.types))); + const templates = filter(types, (t) => !!(t.flags & 134217728 /* TemplateLiteral */) && isPatternLiteralType(t)); if (templates.length) { let i = types.length; while (i > 0) { @@ -59815,19 +59815,14 @@ ${lanes.join("\n")} function getConstituentCountOfTypes(types) { return reduceLeft(types, (n, t) => n + getConstituentCount(t), 0); } - function areIntersectedTypesAvoidingPrimitiveReduction(types, primitiveFlags = 4 /* String */ | 8 /* Number */ | 64 /* BigInt */) { - if (types.length !== 2) { - return false; - } - const [t1, t2] = types; - return !!(t1.flags & primitiveFlags) && t2 === emptyTypeLiteralType || !!(t2.flags & primitiveFlags) && t1 === emptyTypeLiteralType; - } function getTypeFromIntersectionTypeNode(node) { const links = getNodeLinks(node); if (!links.resolvedType) { const aliasSymbol = getAliasSymbolForTypeNode(node); const types = map(node.types, getTypeFromTypeNode); - const noSupertypeReduction = areIntersectedTypesAvoidingPrimitiveReduction(types); + const emptyIndex = types.length === 2 ? types.indexOf(emptyTypeLiteralType) : -1; + const t = emptyIndex >= 0 ? types[1 - emptyIndex] : unknownType; + const noSupertypeReduction = !!(t.flags & (4 /* String */ | 8 /* Number */ | 64 /* BigInt */) || t.flags & 134217728 /* TemplateLiteral */ && isPatternLiteralType(t)); links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction); } return links.resolvedType; @@ -60039,11 +60034,6 @@ ${lanes.join("\n")} } function createTemplateLiteralType(texts, types) { const type = createType(134217728 /* TemplateLiteral */); - type.objectFlags = getPropagatingFlagsOfTypes( - types, - /*excludeKinds*/ - 98304 /* Nullable */ - ); type.texts = texts; type.types = types; return type; @@ -60338,7 +60328,15 @@ ${lanes.join("\n")} } function isPatternLiteralPlaceholderType(type) { if (type.flags & 2097152 /* Intersection */) { - return !isGenericType(type) && some(type.types, (t) => !!(t.flags & (2944 /* Literal */ | 98304 /* Nullable */)) || isPatternLiteralPlaceholderType(t)); + let seenPlaceholder = false; + for (const t of type.types) { + if (t.flags & (2944 /* Literal */ | 98304 /* Nullable */) || isPatternLiteralPlaceholderType(t)) { + seenPlaceholder = true; + } else if (!(t.flags & 524288 /* Object */)) { + return false; + } + } + return seenPlaceholder; } return !!(type.flags & (1 /* Any */ | 4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) || isPatternLiteralType(type); } @@ -60355,7 +60353,7 @@ ${lanes.join("\n")} return !!(getGenericObjectFlags(type) & 8388608 /* IsGenericIndexType */); } function getGenericObjectFlags(type) { - if (type.flags & (3145728 /* UnionOrIntersection */ | 134217728 /* TemplateLiteral */)) { + if (type.flags & 3145728 /* UnionOrIntersection */) { if (!(type.objectFlags & 2097152 /* IsGenericTypeComputed */)) { type.objectFlags |= 2097152 /* IsGenericTypeComputed */ | reduceLeft(type.types, (flags, t) => flags | getGenericObjectFlags(t), 0); } @@ -60367,7 +60365,7 @@ ${lanes.join("\n")} } return type.objectFlags & 12582912 /* IsGenericType */; } - return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 4194304 /* IsGenericObjectType */ : 0) | (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 8388608 /* IsGenericIndexType */ : 0); + return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 4194304 /* IsGenericObjectType */ : 0) | (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 8388608 /* IsGenericIndexType */ : 0); } function getSimplifiedType(type, writing) { return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) : type; @@ -61393,7 +61391,7 @@ ${lanes.join("\n")} result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) : target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) : instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments); target.instantiations.set(id, result); const resultObjectFlags = getObjectFlags(result); - if (result.flags & 138117121 /* ObjectFlagsType */ && !(resultObjectFlags & 524288 /* CouldContainTypeVariablesComputed */)) { + if (result.flags & 3899393 /* ObjectFlagsType */ && !(resultObjectFlags & 524288 /* CouldContainTypeVariablesComputed */)) { const resultCouldContainTypeVariables = some(typeArguments, couldContainTypeVariables); if (!(getObjectFlags(result) & 524288 /* CouldContainTypeVariablesComputed */)) { if (resultObjectFlags & (32 /* Mapped */ | 16 /* Anonymous */ | 4 /* Reference */)) { @@ -66107,8 +66105,8 @@ ${lanes.join("\n")} if (objectFlags & 524288 /* CouldContainTypeVariablesComputed */) { return !!(objectFlags & 1048576 /* CouldContainTypeVariables */); } - const result = !!(type.flags & 465829888 /* Instantiable */ || type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || some(getTypeArguments(type), couldContainTypeVariables)) || objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations || objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 4194304 /* ObjectRestType */ | 8388608 /* InstantiationExpressionType */)) || type.flags & (3145728 /* UnionOrIntersection */ | 134217728 /* TemplateLiteral */) && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && some(type.types, couldContainTypeVariables)); - if (type.flags & 138117121 /* ObjectFlagsType */) { + const result = !!(type.flags & 465829888 /* Instantiable */ || type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || some(getTypeArguments(type), couldContainTypeVariables)) || objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations || objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 4194304 /* ObjectRestType */ | 8388608 /* InstantiationExpressionType */)) || type.flags & 3145728 /* UnionOrIntersection */ && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && some(type.types, couldContainTypeVariables)); + if (type.flags & 3899393 /* ObjectFlagsType */) { type.objectFlags |= 524288 /* CouldContainTypeVariablesComputed */ | (result ? 1048576 /* CouldContainTypeVariables */ : 0); } return result; @@ -68626,10 +68624,10 @@ ${lanes.join("\n")} if (isMatchingConstructorReference(right)) { return narrowTypeByConstructor(type, operator, left, assumeTrue); } - if (isBooleanLiteral(right)) { + if (isBooleanLiteral(right) && !isAccessExpression(left)) { return narrowTypeByBooleanComparison(type, left, right, operator, assumeTrue); } - if (isBooleanLiteral(left)) { + if (isBooleanLiteral(left) && !isAccessExpression(right)) { return narrowTypeByBooleanComparison(type, right, left, operator, assumeTrue); } break; @@ -135680,7 +135678,7 @@ ${lanes.join("\n")} options ), setExternalModuleIndicator: getSetExternalModuleIndicator(options), - jsDocParsingMode: 1 /* ParseNone */ + jsDocParsingMode: transpileOptions.jsDocParsingMode ?? 0 /* ParseAll */ } ); if (transpileOptions.moduleName) { diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index ba15aee6695a6..1cfedae7028cb 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -54,7 +54,7 @@ var path = __toESM(require("path")); // src/compiler/corePublic.ts var versionMajorMinor = "5.3"; -var version = "5.3.2"; +var version = "5.3.3"; // src/compiler/core.ts var emptyArray = []; @@ -3112,7 +3112,7 @@ var TypeFlags = /* @__PURE__ */ ((TypeFlags2) => { TypeFlags2[TypeFlags2["InstantiablePrimitive"] = 406847488] = "InstantiablePrimitive"; TypeFlags2[TypeFlags2["Instantiable"] = 465829888] = "Instantiable"; TypeFlags2[TypeFlags2["StructuredOrInstantiable"] = 469499904] = "StructuredOrInstantiable"; - TypeFlags2[TypeFlags2["ObjectFlagsType"] = 138117121] = "ObjectFlagsType"; + TypeFlags2[TypeFlags2["ObjectFlagsType"] = 3899393] = "ObjectFlagsType"; TypeFlags2[TypeFlags2["Simplifiable"] = 25165824] = "Simplifiable"; TypeFlags2[TypeFlags2["Singleton"] = 67358815] = "Singleton"; TypeFlags2[TypeFlags2["Narrowable"] = 536624127] = "Narrowable"; diff --git a/package-lock.json b/package-lock.json index ae6ef5c3bfe5e..de764a5f20ac4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "typescript", - "version": "5.3.1-rc", + "version": "5.3.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "typescript", - "version": "5.3.1-rc", + "version": "5.3.3", "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", diff --git a/package.json b/package.json index ee3d25aa945d2..20f449beaa886 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "https://www.typescriptlang.org/", - "version": "5.3.2", + "version": "5.3.3", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9ad699f1adcb0..5fa46f7972072 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16893,10 +16893,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function removeStringLiteralsMatchedByTemplateLiterals(types: Type[]) { - const templates = filter(types, t => - !!(t.flags & TypeFlags.TemplateLiteral) && - isPatternLiteralType(t) && - (t as TemplateLiteralType).types.every(t => !(t.flags & TypeFlags.Intersection) || !areIntersectedTypesAvoidingPrimitiveReduction((t as IntersectionType).types))) as TemplateLiteralType[]; + const templates = filter(types, t => !!(t.flags & TypeFlags.TemplateLiteral) && isPatternLiteralType(t)) as TemplateLiteralType[]; if (templates.length) { let i = types.length; while (i > 0) { @@ -17407,20 +17404,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return reduceLeft(types, (n, t) => n + getConstituentCount(t), 0); } - function areIntersectedTypesAvoidingPrimitiveReduction(types: Type[], primitiveFlags = TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt): boolean { - if (types.length !== 2) { - return false; - } - const [t1, t2] = types; - return !!(t1.flags & primitiveFlags) && t2 === emptyTypeLiteralType || !!(t2.flags & primitiveFlags) && t1 === emptyTypeLiteralType; - } - function getTypeFromIntersectionTypeNode(node: IntersectionTypeNode): Type { const links = getNodeLinks(node); if (!links.resolvedType) { const aliasSymbol = getAliasSymbolForTypeNode(node); const types = map(node.types, getTypeFromTypeNode); - const noSupertypeReduction = areIntersectedTypesAvoidingPrimitiveReduction(types); + // We perform no supertype reduction for X & {} or {} & X, where X is one of string, number, bigint, + // or a pattern literal template type. This enables union types like "a" | "b" | string & {} or + // "aa" | "ab" | `a${string}` which preserve the literal types for purposes of statement completion. + const emptyIndex = types.length === 2 ? types.indexOf(emptyTypeLiteralType) : -1; + const t = emptyIndex >= 0 ? types[1 - emptyIndex] : unknownType; + const noSupertypeReduction = !!(t.flags & (TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt) || t.flags & TypeFlags.TemplateLiteral && isPatternLiteralType(t)); links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction); } return links.resolvedType; @@ -17703,7 +17697,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function createTemplateLiteralType(texts: readonly string[], types: readonly Type[]) { const type = createType(TypeFlags.TemplateLiteral) as TemplateLiteralType; - type.objectFlags = getPropagatingFlagsOfTypes(types, /*excludeKinds*/ TypeFlags.Nullable); type.texts = texts; type.types = types; return type; @@ -18028,12 +18021,25 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function isPatternLiteralPlaceholderType(type: Type): boolean { if (type.flags & TypeFlags.Intersection) { - return !isGenericType(type) && some((type as IntersectionType).types, t => !!(t.flags & (TypeFlags.Literal | TypeFlags.Nullable)) || isPatternLiteralPlaceholderType(t)); + // Return true if the intersection consists of one or more placeholders and zero or + // more object type tags. + let seenPlaceholder = false; + for (const t of (type as IntersectionType).types) { + if (t.flags & (TypeFlags.Literal | TypeFlags.Nullable) || isPatternLiteralPlaceholderType(t)) { + seenPlaceholder = true; + } + else if (!(t.flags & TypeFlags.Object)) { + return false; + } + } + return seenPlaceholder; } return !!(type.flags & (TypeFlags.Any | TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt)) || isPatternLiteralType(type); } 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); } @@ -18051,12 +18057,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getGenericObjectFlags(type: Type): ObjectFlags { - if (type.flags & (TypeFlags.UnionOrIntersection | TypeFlags.TemplateLiteral)) { - if (!((type as UnionOrIntersectionType | TemplateLiteralType).objectFlags & ObjectFlags.IsGenericTypeComputed)) { - (type as UnionOrIntersectionType | TemplateLiteralType).objectFlags |= ObjectFlags.IsGenericTypeComputed | - reduceLeft((type as UnionOrIntersectionType | TemplateLiteralType).types, (flags, t) => flags | getGenericObjectFlags(t), 0); + if (type.flags & (TypeFlags.UnionOrIntersection)) { + if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericTypeComputed)) { + (type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericTypeComputed | + reduceLeft((type as UnionOrIntersectionType).types, (flags, t) => flags | getGenericObjectFlags(t), 0); } - return (type as UnionOrIntersectionType | TemplateLiteralType).objectFlags & ObjectFlags.IsGenericType; + return (type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericType; } if (type.flags & TypeFlags.Substitution) { if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericTypeComputed)) { @@ -18066,7 +18072,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return (type as SubstitutionType).objectFlags & ObjectFlags.IsGenericType; } return (type.flags & TypeFlags.InstantiableNonPrimitive || isGenericMappedType(type) || isGenericTupleType(type) ? ObjectFlags.IsGenericObjectType : 0) | - (type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.StringMapping) && !isPatternLiteralType(type) ? ObjectFlags.IsGenericIndexType : 0); + (type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) && !isPatternLiteralType(type) ? ObjectFlags.IsGenericIndexType : 0); } function getSimplifiedType(type: Type, writing: boolean): Type { @@ -24734,7 +24740,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations || objectFlags & (ObjectFlags.Mapped | ObjectFlags.ReverseMapped | ObjectFlags.ObjectRestType | ObjectFlags.InstantiationExpressionType) ) || - type.flags & (TypeFlags.UnionOrIntersection | TypeFlags.TemplateLiteral) && !(type.flags & TypeFlags.EnumLiteral) && !isNonGenericTopLevelType(type) && some((type as UnionOrIntersectionType | TemplateLiteralType).types, couldContainTypeVariables)); + type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && !isNonGenericTopLevelType(type) && some((type as UnionOrIntersectionType).types, couldContainTypeVariables)); if (type.flags & TypeFlags.ObjectFlagsType) { (type as ObjectFlagsType).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed | (result ? ObjectFlags.CouldContainTypeVariables : 0); } @@ -27886,10 +27892,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (isMatchingConstructorReference(right)) { return narrowTypeByConstructor(type, operator, left, assumeTrue); } - if (isBooleanLiteral(right)) { + if (isBooleanLiteral(right) && !isAccessExpression(left)) { return narrowTypeByBooleanComparison(type, left, right, operator, assumeTrue); } - if (isBooleanLiteral(left)) { + if (isBooleanLiteral(left) && !isAccessExpression(right)) { return narrowTypeByBooleanComparison(type, right, left, operator, assumeTrue); } break; diff --git a/src/compiler/corePublic.ts b/src/compiler/corePublic.ts index 5f4184600cb19..e8ed5c9d59f13 100644 --- a/src/compiler/corePublic.ts +++ b/src/compiler/corePublic.ts @@ -4,7 +4,7 @@ export const versionMajorMinor = "5.3"; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types -export const version = "5.3.2" as string; +export const version = "5.3.3" as string; /** * Type of objects whose values are all of the same type. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 927720e580da8..7821c32218eb8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -858,7 +858,7 @@ export const enum ModifierFlags { Protected = 1 << 2, // Property/Method Readonly = 1 << 3, // Property/Method Override = 1 << 4, // Override method. - + // Syntactic-only modifiers Export = 1 << 5, // Declarations Abstract = 1 << 6, // Class/Method/ConstructSignature @@ -3663,10 +3663,10 @@ export interface ImportClause extends NamedDeclaration { export type AssertionKey = ImportAttributeName; /** @deprecated */ -export type AssertEntry = ImportAttribute; +export interface AssertEntry extends ImportAttribute {} /** @deprecated */ -export type AssertClause = ImportAttributes; +export interface AssertClause extends ImportAttributes {} export type ImportAttributeName = Identifier | StringLiteral; @@ -6129,7 +6129,7 @@ export const enum TypeFlags { Instantiable = InstantiableNonPrimitive | InstantiablePrimitive, StructuredOrInstantiable = StructuredType | Instantiable, /** @internal */ - ObjectFlagsType = Any | Nullable | Never | Object | Union | Intersection | TemplateLiteral, + ObjectFlagsType = Any | Nullable | Never | Object | Union | Intersection, /** @internal */ Simplifiable = IndexedAccess | Conditional, /** @internal */ @@ -6288,7 +6288,7 @@ export const enum ObjectFlags { /** @internal */ IdenticalBaseTypeExists = 1 << 26, // has a defined cachedEquivalentBaseType member - // Flags that require TypeFlags.UnionOrIntersection, TypeFlags.Substitution, or TypeFlags.TemplateLiteral + // Flags that require TypeFlags.UnionOrIntersection or TypeFlags.Substitution /** @internal */ IsGenericTypeComputed = 1 << 21, // IsGenericObjectType flag has been computed /** @internal */ @@ -6315,7 +6315,7 @@ export const enum ObjectFlags { } /** @internal */ -export type ObjectFlagsType = NullableType | ObjectType | UnionType | IntersectionType | TemplateLiteralType; +export type ObjectFlagsType = NullableType | ObjectType | UnionType | IntersectionType; // Object types (TypeFlags.ObjectType) // dprint-ignore @@ -6674,8 +6674,6 @@ export interface ConditionalType extends InstantiableType { } export interface TemplateLiteralType extends InstantiableType { - /** @internal */ - objectFlags: ObjectFlags; texts: readonly string[]; // Always one element longer than types types: readonly Type[]; // Always at least one element } @@ -7404,7 +7402,7 @@ export interface CommandLineOptionBase { isFilePath?: boolean; // True if option value is a path or fileName shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help' description?: DiagnosticMessage; // The message describing what the command line switch does. - defaultValueDescription?: string | number | boolean | DiagnosticMessage; // The message describing what the dafault value is. string type is prepared for fixed chosen like "false" which do not need I18n. + defaultValueDescription?: string | number | boolean | DiagnosticMessage | undefined; // The message describing what the dafault value is. string type is prepared for fixed chosen like "false" which do not need I18n. paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter isTSConfigOnly?: boolean; // True if option can only be specified via tsconfig.json file isCommandLineOnly?: boolean; diff --git a/src/server/project.ts b/src/server/project.ts index e0a21ed7701d2..8eda935c575b4 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -347,7 +347,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo readonly realpath?: (path: string) => string; /** @internal */ - hasInvalidatedResolutions: HasInvalidatedResolutions | undefined; + hasInvalidatedResolutions?: HasInvalidatedResolutions | undefined; /** @internal */ hasInvalidatedLibResolutions: HasInvalidatedLibResolutions | undefined; diff --git a/src/services/transpile.ts b/src/services/transpile.ts index 9637387afa093..a15b48d8d7436 100644 --- a/src/services/transpile.ts +++ b/src/services/transpile.ts @@ -36,6 +36,7 @@ export interface TranspileOptions { moduleName?: string; renamedDependencies?: MapLike; transformers?: CustomTransformers; + jsDocParsingMode?: JSDocParsingMode; } export interface TranspileOutput { @@ -121,7 +122,7 @@ export function transpileModule(input: string, transpileOptions: TranspileOption languageVersion: getEmitScriptTarget(options), impliedNodeFormat: getImpliedNodeFormatForFile(toPath(inputFileName, "", compilerHost.getCanonicalFileName), /*packageJsonInfoCache*/ undefined, compilerHost, options), setExternalModuleIndicator: getSetExternalModuleIndicator(options), - jsDocParsingMode: JSDocParsingMode.ParseNone, + jsDocParsingMode: transpileOptions.jsDocParsingMode ?? JSDocParsingMode.ParseAll, }, ); if (transpileOptions.moduleName) { diff --git a/src/services/types.ts b/src/services/types.ts index c1d92f808dccf..5758b4402cffc 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -337,7 +337,7 @@ export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalR */ readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[]; realpath?(path: string): string; - /** @internal */ createHash?(data: string): string; + /** @internal */ createHash?: ((data: string) => string) | undefined; /* * Unlike `realpath and `readDirectory`, `readFile` and `fileExists` are now _required_ @@ -390,9 +390,9 @@ export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalR * If provided along with custom resolveLibrary, used to determine if we should redo library resolutions * @internal */ - hasInvalidatedLibResolutions?(libFileName: string): boolean; + hasInvalidatedLibResolutions?: ((libFileName: string) => boolean) | undefined; - /** @internal */ hasInvalidatedResolutions?: HasInvalidatedResolutions; + /** @internal */ hasInvalidatedResolutions?: HasInvalidatedResolutions | undefined; /** @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames; /** @internal */ getGlobalTypingsCacheLocation?(): string | undefined; /** @internal */ getSymlinkCache?(files?: readonly SourceFile[]): SymlinkCache; @@ -429,7 +429,7 @@ export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalR /** @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined, optionOptions: CompilerOptions): void; /** @internal */ getIncompleteCompletionsCache?(): IncompleteCompletionsCache; - jsDocParsingMode?: JSDocParsingMode; + jsDocParsingMode?: JSDocParsingMode | undefined; } /** @internal */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 5ee1d5258cb01..754fc50cdd483 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6018,9 +6018,11 @@ declare namespace ts { /** @deprecated */ type AssertionKey = ImportAttributeName; /** @deprecated */ - type AssertEntry = ImportAttribute; + interface AssertEntry extends ImportAttribute { + } /** @deprecated */ - type AssertClause = ImportAttributes; + interface AssertClause extends ImportAttributes { + } type ImportAttributeName = Identifier | StringLiteral; interface ImportAttribute extends Node { readonly kind: SyntaxKind.ImportAttribute; @@ -10416,7 +10418,7 @@ declare namespace ts { installPackage?(options: InstallPackageOptions): Promise; writeFile?(fileName: string, content: string): void; getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined; - jsDocParsingMode?: JSDocParsingMode; + jsDocParsingMode?: JSDocParsingMode | undefined; } type WithMetadata = T & { metadata?: unknown; @@ -11612,6 +11614,7 @@ declare namespace ts { moduleName?: string; renamedDependencies?: MapLike; transformers?: CustomTransformers; + jsDocParsingMode?: JSDocParsingMode; } interface TranspileOutput { outputText: string; diff --git a/tests/baselines/reference/controlFlowOptionalChain3.errors.txt b/tests/baselines/reference/controlFlowOptionalChain3.errors.txt new file mode 100644 index 0000000000000..15a8997f0376e --- /dev/null +++ b/tests/baselines/reference/controlFlowOptionalChain3.errors.txt @@ -0,0 +1,49 @@ +controlFlowOptionalChain3.tsx(30,8): error TS18048: 'foo' is possibly 'undefined'. +controlFlowOptionalChain3.tsx(36,31): error TS18048: 'options' is possibly 'undefined'. + + +==== controlFlowOptionalChain3.tsx (2 errors) ==== + /// + + // https://github.com/microsoft/TypeScript/issues/56482 + + import React from "react"; + + interface Foo { + bar: boolean; + } + + function test1(foo: Foo | undefined) { + if (foo?.bar === false) { + foo; + } + foo; + } + + function test2(foo: Foo | undefined) { + if (foo?.bar === false) { + foo; + } else { + foo; + } + } + + function Test3({ foo }: { foo: Foo | undefined }) { + return ( +
+ {foo?.bar === false && "foo"} + {foo.bar ? "true" : "false"} + ~~~ +!!! error TS18048: 'foo' is possibly 'undefined'. +
+ ); + } + + function test4(options?: { a?: boolean; b?: boolean }) { + if (options?.a === false || options.b) { + ~~~~~~~ +!!! error TS18048: 'options' is possibly 'undefined'. + options; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowOptionalChain3.symbols b/tests/baselines/reference/controlFlowOptionalChain3.symbols new file mode 100644 index 0000000000000..714e32bd6e1ee --- /dev/null +++ b/tests/baselines/reference/controlFlowOptionalChain3.symbols @@ -0,0 +1,98 @@ +//// [tests/cases/conformance/controlFlow/controlFlowOptionalChain3.tsx] //// + +=== controlFlowOptionalChain3.tsx === +/// + +// https://github.com/microsoft/TypeScript/issues/56482 + +import React from "react"; +>React : Symbol(React, Decl(controlFlowOptionalChain3.tsx, 4, 6)) + +interface Foo { +>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.tsx, 4, 26)) + + bar: boolean; +>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) +} + +function test1(foo: Foo | undefined) { +>test1 : Symbol(test1, Decl(controlFlowOptionalChain3.tsx, 8, 1)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 10, 15)) +>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.tsx, 4, 26)) + + if (foo?.bar === false) { +>foo?.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 10, 15)) +>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) + + foo; +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 10, 15)) + } + foo; +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 10, 15)) +} + +function test2(foo: Foo | undefined) { +>test2 : Symbol(test2, Decl(controlFlowOptionalChain3.tsx, 15, 1)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 17, 15)) +>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.tsx, 4, 26)) + + if (foo?.bar === false) { +>foo?.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 17, 15)) +>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) + + foo; +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 17, 15)) + + } else { + foo; +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 17, 15)) + } +} + +function Test3({ foo }: { foo: Foo | undefined }) { +>Test3 : Symbol(Test3, Decl(controlFlowOptionalChain3.tsx, 23, 1)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 25, 16)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 25, 25)) +>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.tsx, 4, 26)) + + return ( +
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114)) + + {foo?.bar === false && "foo"} +>foo?.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 25, 16)) +>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) + + {foo.bar ? "true" : "false"} +>foo.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 25, 16)) +>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) + +
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114)) + + ); +} + +function test4(options?: { a?: boolean; b?: boolean }) { +>test4 : Symbol(test4, Decl(controlFlowOptionalChain3.tsx, 32, 1)) +>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15)) +>a : Symbol(a, Decl(controlFlowOptionalChain3.tsx, 34, 26)) +>b : Symbol(b, Decl(controlFlowOptionalChain3.tsx, 34, 39)) + + if (options?.a === false || options.b) { +>options?.a : Symbol(a, Decl(controlFlowOptionalChain3.tsx, 34, 26)) +>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15)) +>a : Symbol(a, Decl(controlFlowOptionalChain3.tsx, 34, 26)) +>options.b : Symbol(b, Decl(controlFlowOptionalChain3.tsx, 34, 39)) +>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15)) +>b : Symbol(b, Decl(controlFlowOptionalChain3.tsx, 34, 39)) + + options; +>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15)) + } +} + diff --git a/tests/baselines/reference/controlFlowOptionalChain3.types b/tests/baselines/reference/controlFlowOptionalChain3.types new file mode 100644 index 0000000000000..2ef7dc502c01a --- /dev/null +++ b/tests/baselines/reference/controlFlowOptionalChain3.types @@ -0,0 +1,110 @@ +//// [tests/cases/conformance/controlFlow/controlFlowOptionalChain3.tsx] //// + +=== controlFlowOptionalChain3.tsx === +/// + +// https://github.com/microsoft/TypeScript/issues/56482 + +import React from "react"; +>React : typeof React + +interface Foo { + bar: boolean; +>bar : boolean +} + +function test1(foo: Foo | undefined) { +>test1 : (foo: Foo | undefined) => void +>foo : Foo | undefined + + if (foo?.bar === false) { +>foo?.bar === false : boolean +>foo?.bar : boolean | undefined +>foo : Foo | undefined +>bar : boolean | undefined +>false : false + + foo; +>foo : Foo + } + foo; +>foo : Foo | undefined +} + +function test2(foo: Foo | undefined) { +>test2 : (foo: Foo | undefined) => void +>foo : Foo | undefined + + if (foo?.bar === false) { +>foo?.bar === false : boolean +>foo?.bar : boolean | undefined +>foo : Foo | undefined +>bar : boolean | undefined +>false : false + + foo; +>foo : Foo + + } else { + foo; +>foo : Foo | undefined + } +} + +function Test3({ foo }: { foo: Foo | undefined }) { +>Test3 : ({ foo }: { foo: Foo | undefined; }) => JSX.Element +>foo : Foo | undefined +>foo : Foo | undefined + + return ( +>(
{foo?.bar === false && "foo"} {foo.bar ? "true" : "false"}
) : JSX.Element + +
+>
{foo?.bar === false && "foo"} {foo.bar ? "true" : "false"}
: JSX.Element +>div : any + + {foo?.bar === false && "foo"} +>foo?.bar === false && "foo" : false | "foo" +>foo?.bar === false : boolean +>foo?.bar : boolean | undefined +>foo : Foo | undefined +>bar : boolean | undefined +>false : false +>"foo" : "foo" + + {foo.bar ? "true" : "false"} +>foo.bar ? "true" : "false" : "false" | "true" +>foo.bar : boolean +>foo : Foo | undefined +>bar : boolean +>"true" : "true" +>"false" : "false" + +
+>div : any + + ); +} + +function test4(options?: { a?: boolean; b?: boolean }) { +>test4 : (options?: { a?: boolean; b?: boolean;}) => void +>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined +>a : boolean | undefined +>b : boolean | undefined + + if (options?.a === false || options.b) { +>options?.a === false || options.b : boolean | undefined +>options?.a === false : boolean +>options?.a : boolean | undefined +>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined +>a : boolean | undefined +>false : false +>options.b : boolean | undefined +>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined +>b : boolean | undefined + + options; +>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined + } +} + diff --git a/tests/baselines/reference/templateLiteralTypesPatterns.errors.txt b/tests/baselines/reference/templateLiteralTypesPatterns.errors.txt index cd82afc83981b..3ead220eb04cd 100644 --- a/tests/baselines/reference/templateLiteralTypesPatterns.errors.txt +++ b/tests/baselines/reference/templateLiteralTypesPatterns.errors.txt @@ -55,7 +55,7 @@ templateLiteralTypesPatterns.ts(129,9): error TS2345: Argument of type '"1.1e-10 templateLiteralTypesPatterns.ts(140,1): error TS2322: Type '`a${string}`' is not assignable to type '`a${number}`'. templateLiteralTypesPatterns.ts(141,1): error TS2322: Type '"bno"' is not assignable to type '`a${any}`'. templateLiteralTypesPatterns.ts(160,7): error TS2322: Type '"anything"' is not assignable to type '`${number} ${number}`'. -templateLiteralTypesPatterns.ts(211,5): error TS2345: Argument of type '"abcTest"' is not assignable to parameter of type '`${`a${string}` & `${string}a`}Test`'. +templateLiteralTypesPatterns.ts(215,5): error TS2345: Argument of type '"abcTest"' is not assignable to parameter of type '`${`a${string}` & `${string}a`}Test`'. ==== templateLiteralTypesPatterns.ts (58 errors) ==== @@ -376,10 +376,14 @@ templateLiteralTypesPatterns.ts(211,5): error TS2345: Argument of type '"abcTest } // repro from https://github.com/microsoft/TypeScript/issues/54177#issuecomment-1538436654 - function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} + function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string}Downcast` & {}) {} conversionTest("testDowncast"); - function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} + function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | {} & `${string}Downcast`) {} conversionTest2("testDowncast"); + function conversionTest3(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} + conversionTest3("testDowncast"); + function conversionTest4(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} + conversionTest4("testDowncast"); function foo(str: `${`a${string}` & `${string}a`}Test`) {} foo("abaTest"); // ok diff --git a/tests/baselines/reference/templateLiteralTypesPatterns.js b/tests/baselines/reference/templateLiteralTypesPatterns.js index d66c794e287a8..8741dda63c2cc 100644 --- a/tests/baselines/reference/templateLiteralTypesPatterns.js +++ b/tests/baselines/reference/templateLiteralTypesPatterns.js @@ -204,10 +204,14 @@ export abstract class BB { } // repro from https://github.com/microsoft/TypeScript/issues/54177#issuecomment-1538436654 -function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} +function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string}Downcast` & {}) {} conversionTest("testDowncast"); -function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} +function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | {} & `${string}Downcast`) {} conversionTest2("testDowncast"); +function conversionTest3(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} +conversionTest3("testDowncast"); +function conversionTest4(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} +conversionTest4("testDowncast"); function foo(str: `${`a${string}` & `${string}a`}Test`) {} foo("abaTest"); // ok @@ -367,6 +371,10 @@ function conversionTest(groupName) { } conversionTest("testDowncast"); function conversionTest2(groupName) { } conversionTest2("testDowncast"); +function conversionTest3(groupName) { } +conversionTest3("testDowncast"); +function conversionTest4(groupName) { } +conversionTest4("testDowncast"); function foo(str) { } foo("abaTest"); // ok foo("abcTest"); // error diff --git a/tests/baselines/reference/templateLiteralTypesPatterns.symbols b/tests/baselines/reference/templateLiteralTypesPatterns.symbols index cc508d2680959..67158ff6db1cd 100644 --- a/tests/baselines/reference/templateLiteralTypesPatterns.symbols +++ b/tests/baselines/reference/templateLiteralTypesPatterns.symbols @@ -488,27 +488,41 @@ export abstract class BB { } // repro from https://github.com/microsoft/TypeScript/issues/54177#issuecomment-1538436654 -function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} +function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string}Downcast` & {}) {} >conversionTest : Symbol(conversionTest, Decl(templateLiteralTypesPatterns.ts, 200, 1)) >groupName : Symbol(groupName, Decl(templateLiteralTypesPatterns.ts, 203, 24)) conversionTest("testDowncast"); >conversionTest : Symbol(conversionTest, Decl(templateLiteralTypesPatterns.ts, 200, 1)) -function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} +function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | {} & `${string}Downcast`) {} >conversionTest2 : Symbol(conversionTest2, Decl(templateLiteralTypesPatterns.ts, 204, 31)) >groupName : Symbol(groupName, Decl(templateLiteralTypesPatterns.ts, 205, 25)) conversionTest2("testDowncast"); >conversionTest2 : Symbol(conversionTest2, Decl(templateLiteralTypesPatterns.ts, 204, 31)) +function conversionTest3(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} +>conversionTest3 : Symbol(conversionTest3, Decl(templateLiteralTypesPatterns.ts, 206, 32)) +>groupName : Symbol(groupName, Decl(templateLiteralTypesPatterns.ts, 207, 25)) + +conversionTest3("testDowncast"); +>conversionTest3 : Symbol(conversionTest3, Decl(templateLiteralTypesPatterns.ts, 206, 32)) + +function conversionTest4(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} +>conversionTest4 : Symbol(conversionTest4, Decl(templateLiteralTypesPatterns.ts, 208, 32)) +>groupName : Symbol(groupName, Decl(templateLiteralTypesPatterns.ts, 209, 25)) + +conversionTest4("testDowncast"); +>conversionTest4 : Symbol(conversionTest4, Decl(templateLiteralTypesPatterns.ts, 208, 32)) + function foo(str: `${`a${string}` & `${string}a`}Test`) {} ->foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 206, 32)) ->str : Symbol(str, Decl(templateLiteralTypesPatterns.ts, 208, 13)) +>foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 210, 32)) +>str : Symbol(str, Decl(templateLiteralTypesPatterns.ts, 212, 13)) foo("abaTest"); // ok ->foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 206, 32)) +>foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 210, 32)) foo("abcTest"); // error ->foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 206, 32)) +>foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 210, 32)) diff --git a/tests/baselines/reference/templateLiteralTypesPatterns.types b/tests/baselines/reference/templateLiteralTypesPatterns.types index d9fbfeec9d8b2..d63799df57018 100644 --- a/tests/baselines/reference/templateLiteralTypesPatterns.types +++ b/tests/baselines/reference/templateLiteralTypesPatterns.types @@ -636,22 +636,40 @@ export abstract class BB { } // repro from https://github.com/microsoft/TypeScript/issues/54177#issuecomment-1538436654 -function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} ->conversionTest : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) => void ->groupName : `${string & {}}Downcast` | "downcast" | "dataDowncast" | "editingDowncast" +function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string}Downcast` & {}) {} +>conversionTest : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | `${string}Downcast` & {}) => void +>groupName : (`${string}Downcast` & {}) | "downcast" | "dataDowncast" | "editingDowncast" conversionTest("testDowncast"); >conversionTest("testDowncast") : void ->conversionTest : (groupName: `${string & {}}Downcast` | "downcast" | "dataDowncast" | "editingDowncast") => void +>conversionTest : (groupName: (`${string}Downcast` & {}) | "downcast" | "dataDowncast" | "editingDowncast") => void >"testDowncast" : "testDowncast" -function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} ->conversionTest2 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) => void ->groupName : "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast` +function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | {} & `${string}Downcast`) {} +>conversionTest2 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | {} & `${string}Downcast`) => void +>groupName : "downcast" | "dataDowncast" | "editingDowncast" | ({} & `${string}Downcast`) conversionTest2("testDowncast"); >conversionTest2("testDowncast") : void ->conversionTest2 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) => void +>conversionTest2 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | ({} & `${string}Downcast`)) => void +>"testDowncast" : "testDowncast" + +function conversionTest3(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} +>conversionTest3 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) => void +>groupName : "downcast" | `${string & {}}Downcast` + +conversionTest3("testDowncast"); +>conversionTest3("testDowncast") : void +>conversionTest3 : (groupName: "downcast" | `${string & {}}Downcast`) => void +>"testDowncast" : "testDowncast" + +function conversionTest4(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} +>conversionTest4 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) => void +>groupName : "downcast" | `${{} & string}Downcast` + +conversionTest4("testDowncast"); +>conversionTest4("testDowncast") : void +>conversionTest4 : (groupName: "downcast" | `${{} & string}Downcast`) => void >"testDowncast" : "testDowncast" function foo(str: `${`a${string}` & `${string}a`}Test`) {} diff --git a/tests/cases/compiler/APILibCheck.ts b/tests/cases/compiler/APILibCheck.ts index 674c2f280a1ea..38821a58b0b76 100644 --- a/tests/cases/compiler/APILibCheck.ts +++ b/tests/cases/compiler/APILibCheck.ts @@ -2,6 +2,7 @@ // @noImplicitAny: true // @strictNullChecks: true // @lib: es2018 +// @exactOptionalPropertyTypes: true // @filename: node_modules/typescript/package.json { diff --git a/tests/cases/conformance/controlFlow/controlFlowOptionalChain3.tsx b/tests/cases/conformance/controlFlow/controlFlowOptionalChain3.tsx new file mode 100644 index 0000000000000..191de7ed68255 --- /dev/null +++ b/tests/cases/conformance/controlFlow/controlFlowOptionalChain3.tsx @@ -0,0 +1,44 @@ +// @strict: true +// @noEmit: true +// @esModuleInterop: true +// @jsx: react + +/// + +// https://github.com/microsoft/TypeScript/issues/56482 + +import React from "react"; + +interface Foo { + bar: boolean; +} + +function test1(foo: Foo | undefined) { + if (foo?.bar === false) { + foo; + } + foo; +} + +function test2(foo: Foo | undefined) { + if (foo?.bar === false) { + foo; + } else { + foo; + } +} + +function Test3({ foo }: { foo: Foo | undefined }) { + return ( +
+ {foo?.bar === false && "foo"} + {foo.bar ? "true" : "false"} +
+ ); +} + +function test4(options?: { a?: boolean; b?: boolean }) { + if (options?.a === false || options.b) { + options; + } +} diff --git a/tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts b/tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts index aeb05ead7ccca..00d36bd722a29 100644 --- a/tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts +++ b/tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts @@ -202,10 +202,14 @@ export abstract class BB { } // repro from https://github.com/microsoft/TypeScript/issues/54177#issuecomment-1538436654 -function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} +function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string}Downcast` & {}) {} conversionTest("testDowncast"); -function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} +function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | {} & `${string}Downcast`) {} conversionTest2("testDowncast"); +function conversionTest3(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} +conversionTest3("testDowncast"); +function conversionTest4(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} +conversionTest4("testDowncast"); function foo(str: `${`a${string}` & `${string}a`}Test`) {} foo("abaTest"); // ok diff --git a/tests/cases/fourslash/stringLiteralCompletionsForOpenEndedTemplateLiteralType.ts b/tests/cases/fourslash/stringLiteralCompletionsForOpenEndedTemplateLiteralType.ts index 92c02a23a2854..c5472fab365ad 100644 --- a/tests/cases/fourslash/stringLiteralCompletionsForOpenEndedTemplateLiteralType.ts +++ b/tests/cases/fourslash/stringLiteralCompletionsForOpenEndedTemplateLiteralType.ts @@ -1,6 +1,6 @@ /// -//// function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} +//// function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string}Downcast` & {}) {} //// conversionTest("/**/"); verify.completions({ marker: "", exact: ["downcast", "dataDowncast", "editingDowncast"] });