diff --git a/lib/tsc.js b/lib/tsc.js index 97db13aa62a50..ab79f9e91feec 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { var ts; (function (ts) { ts.versionMajorMinor = "4.8"; - ts.version = "4.8.2"; + ts.version = "4.8.3"; var NativeCollections; (function (NativeCollections) { var globals = typeof globalThis !== "undefined" ? globalThis : @@ -6031,7 +6031,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -36545,7 +36545,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -36560,7 +36560,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { var getCanonicalFileName = ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames }); var commonSourceDirGuesses = []; if (state.compilerOptions.rootDir || (state.compilerOptions.composite && state.compilerOptions.configFilePath)) { @@ -36590,7 +36590,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { var pathFragment = finalPath.slice(candidateDir.length + 1); var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); var jsAndDtsExtensions = [".mjs", ".cjs", ".js", ".json", ".d.mts", ".d.cts", ".d.ts"]; @@ -41875,40 +41875,60 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default", node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export="); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default", node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export="); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); + } + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, undefined, false); - return exportDefaultSymbol; + } + else if (hasSyntheticDefault || hasDefaultOnly) { + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, undefined, false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267: return node.parent.moduleSpecifier; + case 265: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268: return node.parent.parent.moduleSpecifier; + case 270: return node.parent.parent.parent.moduleSpecifier; + case 275: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -41980,7 +42000,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); @@ -42014,29 +42034,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default")) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default")) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -42082,6 +42106,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default") { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -42103,6 +42134,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default") { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, false, dontResolveAlias); @@ -51674,7 +51712,7 @@ var ts; return includes & 8388608 ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304) { - return includes & 32768 ? undefinedType : nullType; + return includes & 16777216 ? neverType : includes & 32768 ? undefinedType : nullType; } if (includes & 4 && includes & (128 | 134217728 | 268435456) || includes & 8 && includes & 256 || @@ -52309,7 +52347,7 @@ var ts; type; } function distributeIndexOverObjectType(objectType, indexType, writing) { - if (objectType.flags & 3145728) { + if (objectType.flags & 1048576 || objectType.flags & 2097152 && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 || writing ? getIntersectionType(types) : getUnionType(types); } @@ -54448,7 +54486,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152) { + if (type.flags & 2097152 && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -55432,7 +55470,7 @@ var ts; if (reportErrors && originalErrorInfo) { resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2, reportErrors, undefined, intersectionState)) { return result; } if (reportErrors && originalErrorInfo && errorInfo) { @@ -55495,8 +55533,8 @@ var ts; if (!c.root.inferTypeParameters && !isDistributionDependent(c.root)) { var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); - if (result = skipTrue ? -1 : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2, false)) { - result &= skipFalse ? -1 : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2, false); + if (result = skipTrue ? -1 : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2, false, undefined, intersectionState)) { + result &= skipFalse ? -1 : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2, false, undefined, intersectionState); if (result) { return result; } @@ -59855,7 +59893,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -59904,7 +59942,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 - || type.flags & 524288 && declaredType !== type + || type.flags & 524288 && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -60024,14 +60062,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2) && assumeTrue && (operator === 36 || operator === 37)) { + if (((type.flags & 2) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304)) && + assumeTrue && + (operator === 36 || operator === 37)) { if (valueType.flags & (131068 | 67108864)) { return valueType; } if (valueType.flags & 524288) { return nonPrimitiveType; } - return type; + if (type.flags & 2) { + return type; + } } if (valueType.flags & 98304) { if (!strictNullChecks) { @@ -60426,7 +60468,9 @@ var ts; !!(type.flags & 465829888 && getBaseConstraintOrType(type).flags & (98304 | 1048576)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304)); + return type.flags & 2097152 ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { var contextualType = (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) && @@ -105437,9 +105481,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); var pseudoUpToDate = false; var usesPrepend = false; var upstreamChangedProject; @@ -105450,7 +105492,7 @@ var ts; if (refStatus.newestInputFileTime && refStatus.newestInputFileTime <= oldestOutputFileTime) { continue; } - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -105501,24 +105543,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { diff --git a/lib/tsserver.js b/lib/tsserver.js index 481cb5866634e..b696263504d68 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -109,7 +109,7 @@ var ts; // 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 - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -8875,7 +8875,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44636,7 +44636,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44656,7 +44656,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44712,7 +44712,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -50994,41 +50994,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); + } + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51118,7 +51138,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51154,29 +51174,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51222,6 +51246,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51243,6 +51274,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62193,7 +62231,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -62883,7 +62921,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65291,7 +65329,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66462,7 +66500,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66554,8 +66592,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71584,7 +71622,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71633,7 +71671,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71766,14 +71804,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72232,7 +72274,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -126929,9 +126973,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -126946,7 +126988,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -127004,25 +127046,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { @@ -171614,13 +171640,13 @@ var ts; return __generator(this, function (_a) { switch (_a.label) { case 0: - ts.Debug.assertIsDefined(host.importServicePlugin); + ts.Debug.assertIsDefined(host.importPlugin); resolvedPath = ts.combinePaths(initialDir, "node_modules"); log("Dynamically importing ".concat(moduleName, " from ").concat(initialDir, " (resolved to ").concat(resolvedPath, ")")); _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, host.importServicePlugin(resolvedPath, moduleName)]; + return [4 /*yield*/, host.importPlugin(resolvedPath, moduleName)]; case 2: result = _a.sent(); return [3 /*break*/, 4]; @@ -172699,7 +172725,7 @@ var ts; }; Project.prototype.enableGlobalPlugins = function (options, pluginConfigOverrides) { var host = this.projectService.host; - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -172756,7 +172782,7 @@ var ts; return __generator(this, function (_a) { switch (_a.label) { case 0: - ts.Debug.assertIsDefined(this.projectService.host.importServicePlugin); + ts.Debug.assertIsDefined(this.projectService.host.importPlugin); log = function (message) { return _this.projectService.logger.info(message); }; logError = function (message) { (errorLogs !== null && errorLogs !== void 0 ? errorLogs : (errorLogs = [])).push(message); @@ -173457,7 +173483,7 @@ var ts; /*@internal*/ ConfiguredProject.prototype.enablePluginsWithOptions = function (options, pluginConfigOverrides) { var host = this.projectService.host; - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -176901,7 +176927,7 @@ var ts; /*@internal*/ ProjectService.prototype.requestEnablePlugin = function (project, pluginConfigEntry, searchPaths, pluginConfigOverrides) { var _a; - if (!this.host.importServicePlugin && !this.host.require) { + if (!this.host.importPlugin && !this.host.require) { this.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -176911,7 +176937,7 @@ var ts; return; } // If the host supports dynamic import, begin enabling the plugin asynchronously. - if (this.host.importServicePlugin) { + if (this.host.importPlugin) { var importPromise = project.beginEnablePluginAsync(pluginConfigEntry, searchPaths, pluginConfigOverrides); (_a = this.pendingPluginEnablements) !== null && _a !== void 0 ? _a : (this.pendingPluginEnablements = new ts.Map()); var promises = this.pendingPluginEnablements.get(project); @@ -181210,7 +181236,7 @@ var ts; setImmediate: function (x) { return setTimeout(x, 0); }, clearImmediate: function (handle) { return clearTimeout(handle); }, /* eslint-enable no-restricted-globals */ - importServicePlugin: function (initialDir, moduleName) { return __awaiter(_this, void 0, void 0, function () { + importPlugin: function (initialDir, moduleName) { return __awaiter(_this, void 0, void 0, function () { var packageRoot, packageJson, packageJsonResponse, e_1, browser, scriptPath, module_1, e_2; return __generator(this, function (_a) { switch (_a.label) { diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 4744d065a38ac..8003ac00a3c64 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -7033,7 +7033,6 @@ declare namespace ts.server { gc?(): void; trace?(s: string): void; require?(initialPath: string, moduleName: string): ModuleImportResult; - importServicePlugin?(root: string, moduleName: string): Promise; } } declare namespace ts.server { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 57276bce88f5a..53b8c929ba8f1 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -303,7 +303,7 @@ var ts; // 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 - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -9069,7 +9069,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44830,7 +44830,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44850,7 +44850,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44906,7 +44906,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -51188,41 +51188,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); + } + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51312,7 +51332,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51348,29 +51368,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51416,6 +51440,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51437,6 +51468,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62387,7 +62425,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -63077,7 +63115,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65485,7 +65523,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66656,7 +66694,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66748,8 +66786,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71778,7 +71816,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71827,7 +71865,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71960,14 +71998,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72426,7 +72468,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -127123,9 +127167,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -127140,7 +127182,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -127198,25 +127240,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { @@ -171808,13 +171834,13 @@ var ts; return __generator(this, function (_a) { switch (_a.label) { case 0: - ts.Debug.assertIsDefined(host.importServicePlugin); + ts.Debug.assertIsDefined(host.importPlugin); resolvedPath = ts.combinePaths(initialDir, "node_modules"); log("Dynamically importing ".concat(moduleName, " from ").concat(initialDir, " (resolved to ").concat(resolvedPath, ")")); _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, host.importServicePlugin(resolvedPath, moduleName)]; + return [4 /*yield*/, host.importPlugin(resolvedPath, moduleName)]; case 2: result = _a.sent(); return [3 /*break*/, 4]; @@ -172893,7 +172919,7 @@ var ts; }; Project.prototype.enableGlobalPlugins = function (options, pluginConfigOverrides) { var host = this.projectService.host; - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -172950,7 +172976,7 @@ var ts; return __generator(this, function (_a) { switch (_a.label) { case 0: - ts.Debug.assertIsDefined(this.projectService.host.importServicePlugin); + ts.Debug.assertIsDefined(this.projectService.host.importPlugin); log = function (message) { return _this.projectService.logger.info(message); }; logError = function (message) { (errorLogs !== null && errorLogs !== void 0 ? errorLogs : (errorLogs = [])).push(message); @@ -173651,7 +173677,7 @@ var ts; /*@internal*/ ConfiguredProject.prototype.enablePluginsWithOptions = function (options, pluginConfigOverrides) { var host = this.projectService.host; - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -177095,7 +177121,7 @@ var ts; /*@internal*/ ProjectService.prototype.requestEnablePlugin = function (project, pluginConfigEntry, searchPaths, pluginConfigOverrides) { var _a; - if (!this.host.importServicePlugin && !this.host.require) { + if (!this.host.importPlugin && !this.host.require) { this.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -177105,7 +177131,7 @@ var ts; return; } // If the host supports dynamic import, begin enabling the plugin asynchronously. - if (this.host.importServicePlugin) { + if (this.host.importPlugin) { var importPromise = project.beginEnablePluginAsync(pluginConfigEntry, searchPaths, pluginConfigOverrides); (_a = this.pendingPluginEnablements) !== null && _a !== void 0 ? _a : (this.pendingPluginEnablements = new ts.Map()); var promises = this.pendingPluginEnablements.get(project); diff --git a/lib/typescript.js b/lib/typescript.js index 49899ec44b380..3c93c04e0e47a 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -294,7 +294,7 @@ var ts; // 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 - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -9060,7 +9060,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44821,7 +44821,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44841,7 +44841,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44897,7 +44897,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -51179,41 +51179,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); + } + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51303,7 +51323,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51339,29 +51359,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51407,6 +51431,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51428,6 +51459,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62378,7 +62416,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -63068,7 +63106,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65476,7 +65514,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66647,7 +66685,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66739,8 +66777,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71769,7 +71807,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71818,7 +71856,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71951,14 +71989,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72417,7 +72459,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -127114,9 +127158,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -127131,7 +127173,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -127189,25 +127231,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 9e45164b7c4c9..61b1259b561f8 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -294,7 +294,7 @@ var ts; // 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 - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -9060,7 +9060,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44821,7 +44821,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44841,7 +44841,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44897,7 +44897,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -51179,41 +51179,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); + } + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51303,7 +51323,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51339,29 +51359,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51407,6 +51431,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51428,6 +51459,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62378,7 +62416,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -63068,7 +63106,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65476,7 +65514,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66647,7 +66685,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66739,8 +66777,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71769,7 +71807,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71818,7 +71856,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71951,14 +71989,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72417,7 +72459,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -127114,9 +127158,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -127131,7 +127173,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -127189,25 +127231,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 8ab14c8266cf2..9303e787c1ef4 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -89,7 +89,7 @@ var ts; // 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 - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -8855,7 +8855,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44616,7 +44616,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44636,7 +44636,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44692,7 +44692,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -50974,41 +50974,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); + } + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51098,7 +51118,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51134,29 +51154,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51202,6 +51226,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51223,6 +51254,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62173,7 +62211,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -62863,7 +62901,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65271,7 +65309,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66442,7 +66480,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66534,8 +66572,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71564,7 +71602,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71613,7 +71651,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71746,14 +71784,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72212,7 +72254,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -126909,9 +126953,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -126926,7 +126968,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -126984,25 +127026,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { diff --git a/package.json b/package.json index b3d43e3a0337c..759cfbc32d810 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "https://www.typescriptlang.org/", - "version": "4.8.2", + "version": "4.8.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 15f384699f09f..194f51256860b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2798,44 +2798,66 @@ namespace ts { function getTargetOfImportClause(node: ImportClause, dontResolveAlias: boolean): Symbol | undefined { const moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - let exportDefaultSymbol: Symbol | undefined; - if (isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, InternalSymbolName.Default, node, dontResolveAlias); - } - - const file = moduleSymbol.declarations?.find(isSourceFile); - const hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - const compilerOptionName = moduleKind >= ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - const exportEqualsSymbol = moduleSymbol.exports!.get(InternalSymbolName.ExportEquals); - const exportAssignment = exportEqualsSymbol!.valueDeclaration; - const err = error(node.name, Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - - if (exportAssignment) { - addRelatedInfo(err, createDiagnosticForNode( - exportAssignment, - Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, - compilerOptionName - )); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + + function getTargetofModuleDefault(moduleSymbol: Symbol, node: ImportClause | ImportOrExportSpecifier, dontResolveAlias: boolean) { + let exportDefaultSymbol: Symbol | undefined; + if (isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, InternalSymbolName.Default, node, dontResolveAlias); + } + + const file = moduleSymbol.declarations?.find(isSourceFile); + const specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + const hasDefaultOnly = isOnlyImportedAsDefault(specifier); + const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + const compilerOptionName = moduleKind >= ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + const exportEqualsSymbol = moduleSymbol.exports!.get(InternalSymbolName.ExportEquals); + const exportAssignment = exportEqualsSymbol!.valueDeclaration; + const err = error(node.name, Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + + if (exportAssignment) { + addRelatedInfo(err, createDiagnosticForNode( + exportAssignment, + Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, + compilerOptionName + )); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - const resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); + } + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, isImportOrExportSpecifier(node) && node.propertyName || node.name); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + const resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + + function getModuleSpecifierForImportOrExport(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportOrExportSpecifier): Expression | undefined { + switch (node.kind) { + case SyntaxKind.ImportClause: return node.parent.moduleSpecifier; + case SyntaxKind.ImportEqualsDeclaration: return isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case SyntaxKind.NamespaceImport: return node.parent.parent.moduleSpecifier; + case SyntaxKind.ImportSpecifier: return node.parent.parent.parent.moduleSpecifier; + case SyntaxKind.ExportSpecifier: return node.parent.parent.moduleSpecifier; + default: return Debug.assertNever(node); } } @@ -2969,38 +2991,42 @@ namespace ts { combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - const moduleName = getFullyQualifiedName(moduleSymbol, node); - const declarationName = declarationNameToString(name); - const suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - const suggestionName = symbolToString(suggestion); - const diagnostic = error(name, Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - addRelatedInfo(diagnostic, - createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestionName) - ); - } - } - else { - if (moduleSymbol.exports?.has(InternalSymbolName.Default)) { - error( - name, - Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, - moduleName, - declarationName - ); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } - function reportNonExportedMember(node: ImportDeclaration | ExportDeclaration | VariableDeclaration, name: Identifier, declarationName: string, moduleSymbol: Symbol, moduleName: string): void { + function errorNoModuleMemberSymbol(moduleSymbol: Symbol, targetSymbol: Symbol, node: Node, name: Identifier) { + const moduleName = getFullyQualifiedName(moduleSymbol, node); + const declarationName = declarationNameToString(name); + const suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + const suggestionName = symbolToString(suggestion); + const diagnostic = error(name, Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + addRelatedInfo(diagnostic, + createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestionName) + ); + } + } + else { + if (moduleSymbol.exports?.has(InternalSymbolName.Default)) { + error( + name, + Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, + moduleName, + declarationName + ); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } + + function reportNonExportedMember(node: Node, name: Identifier, declarationName: string, moduleSymbol: Symbol, moduleName: string): void { const localSymbol = moduleSymbol.valueDeclaration?.locals?.get(name.escapedText); const exports = moduleSymbol.exports; if (localSymbol) { @@ -3025,7 +3051,7 @@ namespace ts { } } - function reportInvalidImportEqualsExportMember(node: ImportDeclaration | ExportDeclaration | VariableDeclaration, name: Identifier, declarationName: string, moduleName: string) { + function reportInvalidImportEqualsExportMember(node: Node, name: Identifier, declarationName: string, moduleName: string) { if (moduleKind >= ModuleKind.ES2015) { const message = getESModuleInterop(compilerOptions) ? Diagnostics._0_can_only_be_imported_by_using_a_default_import : Diagnostics._0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import; @@ -3046,6 +3072,13 @@ namespace ts { } function getTargetOfImportSpecifier(node: ImportSpecifier | BindingElement, dontResolveAlias: boolean): Symbol | undefined { + if (isImportSpecifier(node) && idText(node.propertyName || node.name) === InternalSymbolName.Default) { + const specifier = getModuleSpecifierForImportOrExport(node); + const moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } const root = isBindingElement(node) ? getRootDeclaration(node) as VariableDeclaration : node.parent.parent.parent; const commonJSPropertyAccess = getCommonJSPropertyAccess(root); const resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -3070,6 +3103,13 @@ namespace ts { } function getTargetOfExportSpecifier(node: ExportSpecifier, meaning: SymbolFlags, dontResolveAlias?: boolean) { + if (idText(node.propertyName || node.name) === InternalSymbolName.Default) { + const specifier = getModuleSpecifierForImportOrExport(node); + const moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } const resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -15094,7 +15134,7 @@ namespace ts { return includes & TypeFlags.IncludesWildcard ? wildcardType : anyType; } if (!strictNullChecks && includes & TypeFlags.Nullable) { - return includes & TypeFlags.Undefined ? undefinedType : nullType; + return includes & TypeFlags.IncludesEmptyObject ? neverType : includes & TypeFlags.Undefined ? undefinedType : nullType; } if (includes & TypeFlags.String && includes & (TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) || includes & TypeFlags.Number && includes & TypeFlags.NumberLiteral || @@ -15834,7 +15874,7 @@ namespace ts { // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & TypeFlags.UnionOrIntersection) { + if (objectType.flags & TypeFlags.Union || objectType.flags & TypeFlags.Intersection && !shouldDeferIndexType(objectType)) { const types = map((objectType as UnionOrIntersectionType).types, t => getSimplifiedType(getIndexedAccessType(t, indexType), writing)); return objectType.flags & TypeFlags.Intersection || writing ? getIntersectionType(types) : getUnionType(types); } @@ -18425,7 +18465,7 @@ namespace ts { if (reduced !== type) { return reduced; } - if (type.flags & TypeFlags.Intersection) { + if (type.flags & TypeFlags.Intersection && some((type as IntersectionType).types, isEmptyAnonymousObjectType)) { const normalizedTypes = sameMap(type.types, t => getNormalizedType(t, writing)); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -19654,7 +19694,7 @@ namespace ts { // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, RecursionFlags.Target, reportErrors)) { + if (result = isRelatedTo(source, constraint, RecursionFlags.Target, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -19748,8 +19788,8 @@ namespace ts { const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); const skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? Ternary.True : isRelatedTo(source, getTrueTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false)) { - result &= skipFalse ? Ternary.True : isRelatedTo(source, getFalseTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false); + if (result = skipTrue ? Ternary.True : isRelatedTo(source, getTrueTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? Ternary.True : isRelatedTo(source, getFalseTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -25023,7 +25063,7 @@ namespace ts { const narrowedPropType = narrowType(propType); return filterType(type, t => { const discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & TypeFlags.Never) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & TypeFlags.Never) && areTypesComparable(narrowedPropType, discriminantType); }); } @@ -25077,7 +25117,7 @@ namespace ts { function narrowByInKeyword(type: Type, name: __String, assumeTrue: boolean) { if (type.flags & TypeFlags.Union - || type.flags & TypeFlags.Object && declaredType !== type + || type.flags & TypeFlags.Object && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || isThisTypeParameter(type) || type.flags & TypeFlags.Intersection && every((type as IntersectionType).types, t => t.symbol !== globalThisSymbol)) { return filterType(type, t => isTypePresencePossible(t, name, assumeTrue)); @@ -25215,14 +25255,19 @@ namespace ts { assumeTrue = !assumeTrue; } const valueType = getTypeOfExpression(value); - if ((type.flags & TypeFlags.Unknown) && assumeTrue && (operator === SyntaxKind.EqualsEqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken)) { + if (((type.flags & TypeFlags.Unknown) || isEmptyAnonymousObjectType(type) && !(valueType.flags & TypeFlags.Nullable)) && + assumeTrue && + (operator === SyntaxKind.EqualsEqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) + ) { if (valueType.flags & (TypeFlags.Primitive | TypeFlags.NonPrimitive)) { return valueType; } if (valueType.flags & TypeFlags.Object) { return nonPrimitiveType; } - return type; + if (type.flags & TypeFlags.Unknown) { + return type; + } } if (valueType.flags & TypeFlags.Nullable) { if (!strictNullChecks) { @@ -25716,8 +25761,10 @@ namespace ts { !!(type.flags & TypeFlags.Instantiable && getBaseConstraintOrType(type).flags & (TypeFlags.Nullable | TypeFlags.Union)); } - function isGenericTypeWithoutNullableConstraint(type: Type) { - return !!(type.flags & TypeFlags.Instantiable && !maybeTypeOfKind(getBaseConstraintOrType(type), TypeFlags.Nullable)); + function isGenericTypeWithoutNullableConstraint(type: Type): boolean { + return type.flags & TypeFlags.Intersection ? + some((type as IntersectionType).types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & TypeFlags.Instantiable && !maybeTypeOfKind(getBaseConstraintOrType(type), TypeFlags.Nullable)); } function hasContextualTypeWithNoGenericTypes(node: Node, checkMode: CheckMode | undefined) { diff --git a/src/compiler/corePublic.ts b/src/compiler/corePublic.ts index b60043e993308..0abc89d49fdf4 100644 --- a/src/compiler/corePublic.ts +++ b/src/compiler/corePublic.ts @@ -5,7 +5,7 @@ namespace ts { // 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 = "4.8.2" as string; + export const version = "4.8.3" as string; /** * Type of objects whose values are all of the same type. diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 45e2cde143ca8..daa315562c02c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2677,7 +2677,7 @@ "category": "Error", "code": 2593 }, - "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag.": { + "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag.": { "category": "Error", "code": 2594 }, diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 3c65e4410bdbd..9e3b15f09580c 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -2227,7 +2227,7 @@ namespace ts { function toAbsolutePath(path: string | undefined): string | undefined; function toAbsolutePath(path: string | undefined): string | undefined { if (path === undefined) return path; - return hostGetCanonicalFileName({ useCaseSensitiveFileNames })(getNormalizedAbsolutePath(path, state.host.getCurrentDirectory?.())); + return getNormalizedAbsolutePath(path, state.host.getCurrentDirectory?.()); } function combineDirectoryPath(root: string, dir: string) { @@ -2249,7 +2249,7 @@ namespace ts { if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true) + && (state.compilerOptions.configFile ? containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true) ) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) @@ -2310,7 +2310,7 @@ namespace ts { for (const commonSourceDirGuess of commonSourceDirGuesses) { const candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (const candidateDir of candidateDirectories) { - if (startsWith(finalPath, candidateDir)) { + if (containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension const pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator const possibleInputBase = combinePaths(commonSourceDirGuess, pathFragment); diff --git a/src/compiler/tsbuildPublic.ts b/src/compiler/tsbuildPublic.ts index 90d00833a9925..476662a93c2e9 100644 --- a/src/compiler/tsbuildPublic.ts +++ b/src/compiler/tsbuildPublic.ts @@ -1694,10 +1694,7 @@ namespace ts { } } - const seenRefs = buildInfoPath ? new Set() : undefined; const buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs?.add(resolvedPath); - /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ let pseudoUpToDate = false; let usesPrepend = false; @@ -1712,7 +1709,7 @@ namespace ts { } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs!, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath!, @@ -1775,22 +1772,9 @@ namespace ts { }; } - function hasSameBuildInfo(state: SolutionBuilderState, buildInfoCacheEntry: BuildInfoCacheEntry, seenRefs: Set, resolvedConfig: ParsedCommandLine, resolvedRefPath: ResolvedConfigFilePath) { - if (seenRefs.has(resolvedRefPath)) return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state: SolutionBuilderState, buildInfoCacheEntry: BuildInfoCacheEntry, resolvedRefPath: ResolvedConfigFilePath) { const refBuildInfo = state.buildInfoCache.get(resolvedRefPath)!; - if (refBuildInfo.path === buildInfoCacheEntry.path) return true; - - if (resolvedConfig.projectReferences) { - // Check references - for (const ref of resolvedConfig.projectReferences) { - const resolvedRef = resolveProjectReferencePath(ref); - const resolvedRefPath = toResolvedConfigFilePath(state, resolvedRef); - const resolvedConfig = parseConfigFile(state, resolvedRef, resolvedRefPath)!; - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state: SolutionBuilderState, project: ParsedCommandLine | undefined, resolvedPath: ResolvedConfigFilePath): UpToDateStatus { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index c6d1513c0771f..3ab9f02741cc1 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -4068,7 +4068,7 @@ namespace ts.server { /*@internal*/ requestEnablePlugin(project: Project, pluginConfigEntry: PluginImport, searchPaths: string[], pluginConfigOverrides: Map | undefined) { - if (!this.host.importServicePlugin && !this.host.require) { + if (!this.host.importPlugin && !this.host.require) { this.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -4080,7 +4080,7 @@ namespace ts.server { } // If the host supports dynamic import, begin enabling the plugin asynchronously. - if (this.host.importServicePlugin) { + if (this.host.importPlugin) { const importPromise = project.beginEnablePluginAsync(pluginConfigEntry, searchPaths, pluginConfigOverrides); this.pendingPluginEnablements ??= new Map(); let promises = this.pendingPluginEnablements.get(project); diff --git a/src/server/project.ts b/src/server/project.ts index 1a27b63d2eaa2..a31574080b049 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -256,12 +256,12 @@ namespace ts.server { /*@internal*/ public static async importServicePluginAsync(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void, logErrors?: (message: string) => void): Promise<{} | undefined> { - Debug.assertIsDefined(host.importServicePlugin); + Debug.assertIsDefined(host.importPlugin); const resolvedPath = combinePaths(initialDir, "node_modules"); log(`Dynamically importing ${moduleName} from ${initialDir} (resolved to ${resolvedPath})`); let result: ModuleImportResult; try { - result = await host.importServicePlugin(resolvedPath, moduleName); + result = await host.importPlugin(resolvedPath, moduleName); } catch (e) { result = { module: undefined, error: e }; @@ -1607,7 +1607,7 @@ namespace ts.server { protected enableGlobalPlugins(options: CompilerOptions, pluginConfigOverrides: Map | undefined): void { const host = this.projectService.host; - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -1658,7 +1658,7 @@ namespace ts.server { */ /*@internal*/ async beginEnablePluginAsync(pluginConfigEntry: PluginImport, searchPaths: string[], pluginConfigOverrides: Map | undefined): Promise { - Debug.assertIsDefined(this.projectService.host.importServicePlugin); + Debug.assertIsDefined(this.projectService.host.importPlugin); let errorLogs: string[] | undefined; const log = (message: string) => this.projectService.logger.info(message); @@ -2522,8 +2522,7 @@ namespace ts.server { /*@internal*/ enablePluginsWithOptions(options: CompilerOptions, pluginConfigOverrides: ESMap | undefined): void { const host = this.projectService.host; - - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } diff --git a/src/server/types.ts b/src/server/types.ts index b19879a94920f..2aa26f1231314 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -20,6 +20,7 @@ declare namespace ts.server { gc?(): void; trace?(s: string): void; require?(initialPath: string, moduleName: string): ModuleImportResult; - importServicePlugin?(root: string, moduleName: string): Promise; + /*@internal*/ + importPlugin?(root: string, moduleName: string): Promise; } } diff --git a/src/testRunner/unittests/tsbuild/containerOnlyReferenced.ts b/src/testRunner/unittests/tsbuild/containerOnlyReferenced.ts index e9eacf1fa657c..595bc509744d5 100644 --- a/src/testRunner/unittests/tsbuild/containerOnlyReferenced.ts +++ b/src/testRunner/unittests/tsbuild/containerOnlyReferenced.ts @@ -7,5 +7,36 @@ namespace ts { commandLineArgs: ["--b", "/src", "--verbose"], edits: noChangeOnlyRuns }); + + verifyTscWithEdits({ + scenario: "containerOnlyReferenced", + subScenario: "when solution is referenced indirectly", + fs: () => loadProjectFromFiles({ + "/src/project1/tsconfig.json": JSON.stringify({ + compilerOptions: { composite: true }, + references: [], + }), + "/src/project2/tsconfig.json": JSON.stringify({ + compilerOptions: { composite: true }, + references: [], + }), + "/src/project2/src/b.ts": "export const b = 10;", + "/src/project3/tsconfig.json": JSON.stringify({ + compilerOptions: { composite: true }, + references: [{ path: "../project1", }, { path: "../project2" }], + }), + "/src/project3/src/c.ts": "export const c = 10;", + "/src/project4/tsconfig.json": JSON.stringify({ + compilerOptions: { composite: true }, + references: [{ path: "../project3" }] + }), + "/src/project4/src/d.ts": "export const d = 10;", + }), + commandLineArgs: ["--b", "/src/project4", "--verbose", "--explainFiles"], + edits: [{ + subScenario: "modify project3 file", + modifyFs: fs => replaceText(fs, "/src/project3/src/c.ts", "c = ", "cc = "), + }], + }); }); } diff --git a/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts b/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts index 69ad855b626df..584b32c33535c 100644 --- a/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts +++ b/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts @@ -262,5 +262,69 @@ a;b; verifyDirSymlink("when import matches disk but directory symlink target does not", `${projectRoot}/XY`, `${projectRoot}/XY`, `./Xy`); verifyDirSymlink("when import and directory symlink target agree but do not match disk", `${projectRoot}/XY`, `${projectRoot}/Xy`, `./Xy`); verifyDirSymlink("when import, directory symlink target, and disk are all different", `${projectRoot}/XY`, `${projectRoot}/Xy`, `./yX`); + + verifyTscWatch({ + scenario: "forceConsistentCasingInFileNames", + subScenario: "with nodeNext resolution", + commandLineArgs: ["--w", "--explainFiles"], + sys: () => createWatchedSystem({ + "/Users/name/projects/web/src/bin.ts": `import { foo } from "yargs";`, + "/Users/name/projects/web/node_modules/@types/yargs/index.d.ts": "export function foo(): void;", + "/Users/name/projects/web/node_modules/@types/yargs/index.d.mts": "export function foo(): void;", + "/Users/name/projects/web/node_modules/@types/yargs/package.json": JSON.stringify({ + name: "yargs", + version: "17.0.12", + exports: { + ".": { + types: { + import: "./index.d.mts", + default: "./index.d.ts" + } + }, + } + }), + "/Users/name/projects/web/tsconfig.json": JSON.stringify({ + compilerOptions: { + moduleResolution: "nodenext", + forceConsistentCasingInFileNames: true, + traceResolution: true, + } + }), + [libFile.path]: libFile.content, + }, { currentDirectory: "/Users/name/projects/web" }), + changes: emptyArray, + }); + + verifyTscWatch({ + scenario: "forceConsistentCasingInFileNames", + subScenario: "self name package reference", + commandLineArgs: ["-w", "--explainFiles"], + sys: () => createWatchedSystem({ + "/Users/name/projects/web/package.json": JSON.stringify({ + name: "@this/package", + type: "module", + exports: { + ".": "./dist/index.js" + } + }), + "/Users/name/projects/web/index.ts": Utils.dedent` + import * as me from "@this/package"; + me.thing(); + export function thing(): void {} + `, + "/Users/name/projects/web/tsconfig.json": JSON.stringify({ + compilerOptions: { + module: "nodenext", + outDir: "./dist", + declarationDir: "./types", + composite: true, + forceConsistentCasingInFileNames: true, + traceResolution: true, + } + }), + "/a/lib/lib.esnext.full.d.ts": libFile.content, + }, { currentDirectory: "/Users/name/projects/web" }), + changes: emptyArray, + }); }); } diff --git a/src/testRunner/unittests/tsserver/webServer.ts b/src/testRunner/unittests/tsserver/webServer.ts index d9f09eb4d4b2d..1e606ff01646d 100644 --- a/src/testRunner/unittests/tsserver/webServer.ts +++ b/src/testRunner/unittests/tsserver/webServer.ts @@ -29,7 +29,7 @@ namespace ts.projectSystem { } } - function setup(logLevel: server.LogLevel | undefined, options?: Partial, importServicePlugin?: server.ServerHost["importServicePlugin"]) { + function setup(logLevel: server.LogLevel | undefined, options?: Partial, importPlugin?: server.ServerHost["importPlugin"]) { const host = createServerHost([libFile], { windowsStyleRoot: "c:/" }); const messages: any[] = []; const webHost: server.WebHost = { @@ -38,7 +38,7 @@ namespace ts.projectSystem { writeMessage: s => messages.push(s), }; const webSys = server.createWebSystem(webHost, emptyArray, () => host.getExecutingFilePath()); - webSys.importServicePlugin = importServicePlugin; + webSys.importPlugin = importPlugin; const logger = logLevel !== undefined ? new server.MainProcessLogger(logLevel, webHost) : nullLogger(); const session = new TestWorkerSession(webSys, webHost, { serverMode: LanguageServiceMode.PartialSemantic, ...options }, logger); return { getMessages: () => messages, clearMessages: () => messages.length = 0, session }; @@ -161,7 +161,7 @@ namespace ts.projectSystem { it("plugins are not loaded immediately", async () => { let pluginModuleInstantiated = false; let pluginInvoked = false; - const importServicePlugin = async (_root: string, _moduleName: string): Promise => { + const importPlugin = async (_root: string, _moduleName: string): Promise => { await Promise.resolve(); // simulate at least a single turn delay pluginModuleInstantiated = true; return { @@ -173,7 +173,7 @@ namespace ts.projectSystem { }; }; - const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin); + const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin); const projectService = session.getProjectService(); session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } }); @@ -201,7 +201,7 @@ namespace ts.projectSystem { const pluginADeferred = Utils.defer(); const pluginBDeferred = Utils.defer(); const log: string[] = []; - const importServicePlugin = async (_root: string, moduleName: string): Promise => { + const importPlugin = async (_root: string, moduleName: string): Promise => { log.push(`request import ${moduleName}`); const promise = moduleName === "plugin-a" ? pluginADeferred.promise : pluginBDeferred.promise; await promise; @@ -215,7 +215,7 @@ namespace ts.projectSystem { }; }; - const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a", "plugin-b"] }, importServicePlugin); + const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a", "plugin-b"] }, importPlugin); const projectService = session.getProjectService(); session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } }); @@ -241,7 +241,7 @@ namespace ts.projectSystem { }); it("sends projectsUpdatedInBackground event", async () => { - const importServicePlugin = async (_root: string, _moduleName: string): Promise => { + const importPlugin = async (_root: string, _moduleName: string): Promise => { await Promise.resolve(); // simulate at least a single turn delay return { module: (() => ({ create: info => info.languageService })) as server.PluginModuleFactory, @@ -249,7 +249,7 @@ namespace ts.projectSystem { }; }; - const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin); + const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin); const projectService = session.getProjectService(); session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } }); @@ -270,7 +270,7 @@ namespace ts.projectSystem { const pluginAShouldLoad = Utils.defer(); const pluginAExternalFilesRequested = Utils.defer(); - const importServicePlugin = async (_root: string, _moduleName: string): Promise => { + const importPlugin = async (_root: string, _moduleName: string): Promise => { // wait until the initial external files are requested from the project service. await pluginAShouldLoad.promise; @@ -287,7 +287,7 @@ namespace ts.projectSystem { }; }; - const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin); + const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin); const projectService = session.getProjectService(); session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } }); @@ -316,7 +316,7 @@ namespace ts.projectSystem { it("project is closed before plugins are loaded", async () => { const pluginALoaded = Utils.defer(); const projectClosed = Utils.defer(); - const importServicePlugin = async (_root: string, _moduleName: string): Promise => { + const importPlugin = async (_root: string, _moduleName: string): Promise => { // mark that the plugin has started loading pluginALoaded.resolve(); @@ -328,7 +328,7 @@ namespace ts.projectSystem { }; }; - const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin); + const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin); const projectService = session.getProjectService(); session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } }); diff --git a/src/webServer/webServer.ts b/src/webServer/webServer.ts index 0cad87dd97b67..c989c00557ba4 100644 --- a/src/webServer/webServer.ts +++ b/src/webServer/webServer.ts @@ -162,7 +162,7 @@ namespace ts.server { clearImmediate: handle => clearTimeout(handle), /* eslint-enable no-restricted-globals */ - importServicePlugin: async (initialDir: string, moduleName: string): Promise => { + importPlugin: async (initialDir: string, moduleName: string): Promise => { const packageRoot = combinePaths(initialDir, moduleName); let packageJson: any | undefined; diff --git a/tests/baselines/reference/NonNullableInNonStrictMode.js b/tests/baselines/reference/NonNullableInNonStrictMode.js new file mode 100644 index 0000000000000..e5a577ed7ba88 --- /dev/null +++ b/tests/baselines/reference/NonNullableInNonStrictMode.js @@ -0,0 +1,21 @@ +//// [NonNullableInNonStrictMode.ts] +// These should all resolve to never + +type T0 = NonNullable; +type T1 = NonNullable; +type T2 = null & {}; +type T3 = undefined & {}; +type T4 = null & undefined; +type T6 = null & { a: string } & {}; + +// Repro from #50519 + +type NonNullableNew = T & {}; +type NonNullableOld = T extends null | undefined ? never : T; + +type IsNullWithoutStrictNullChecks = NonNullableNew; +type IsAlwaysNever = NonNullableOld; + + +//// [NonNullableInNonStrictMode.js] +// These should all resolve to never diff --git a/tests/baselines/reference/NonNullableInNonStrictMode.symbols b/tests/baselines/reference/NonNullableInNonStrictMode.symbols new file mode 100644 index 0000000000000..b01bdc9cfbeee --- /dev/null +++ b/tests/baselines/reference/NonNullableInNonStrictMode.symbols @@ -0,0 +1,45 @@ +=== tests/cases/compiler/NonNullableInNonStrictMode.ts === +// These should all resolve to never + +type T0 = NonNullable; +>T0 : Symbol(T0, Decl(NonNullableInNonStrictMode.ts, 0, 0)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) + +type T1 = NonNullable; +>T1 : Symbol(T1, Decl(NonNullableInNonStrictMode.ts, 2, 28)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) + +type T2 = null & {}; +>T2 : Symbol(T2, Decl(NonNullableInNonStrictMode.ts, 3, 33)) + +type T3 = undefined & {}; +>T3 : Symbol(T3, Decl(NonNullableInNonStrictMode.ts, 4, 20)) + +type T4 = null & undefined; +>T4 : Symbol(T4, Decl(NonNullableInNonStrictMode.ts, 5, 25)) + +type T6 = null & { a: string } & {}; +>T6 : Symbol(T6, Decl(NonNullableInNonStrictMode.ts, 6, 27)) +>a : Symbol(a, Decl(NonNullableInNonStrictMode.ts, 7, 18)) + +// Repro from #50519 + +type NonNullableNew = T & {}; +>NonNullableNew : Symbol(NonNullableNew, Decl(NonNullableInNonStrictMode.ts, 7, 36)) +>T : Symbol(T, Decl(NonNullableInNonStrictMode.ts, 11, 20)) +>T : Symbol(T, Decl(NonNullableInNonStrictMode.ts, 11, 20)) + +type NonNullableOld = T extends null | undefined ? never : T; +>NonNullableOld : Symbol(NonNullableOld, Decl(NonNullableInNonStrictMode.ts, 11, 32)) +>T : Symbol(T, Decl(NonNullableInNonStrictMode.ts, 12, 20)) +>T : Symbol(T, Decl(NonNullableInNonStrictMode.ts, 12, 20)) +>T : Symbol(T, Decl(NonNullableInNonStrictMode.ts, 12, 20)) + +type IsNullWithoutStrictNullChecks = NonNullableNew; +>IsNullWithoutStrictNullChecks : Symbol(IsNullWithoutStrictNullChecks, Decl(NonNullableInNonStrictMode.ts, 12, 64)) +>NonNullableNew : Symbol(NonNullableNew, Decl(NonNullableInNonStrictMode.ts, 7, 36)) + +type IsAlwaysNever = NonNullableOld; +>IsAlwaysNever : Symbol(IsAlwaysNever, Decl(NonNullableInNonStrictMode.ts, 14, 58)) +>NonNullableOld : Symbol(NonNullableOld, Decl(NonNullableInNonStrictMode.ts, 11, 32)) + diff --git a/tests/baselines/reference/NonNullableInNonStrictMode.types b/tests/baselines/reference/NonNullableInNonStrictMode.types new file mode 100644 index 0000000000000..cb2894ce0526b --- /dev/null +++ b/tests/baselines/reference/NonNullableInNonStrictMode.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/NonNullableInNonStrictMode.ts === +// These should all resolve to never + +type T0 = NonNullable; +>T0 : never +>null : null + +type T1 = NonNullable; +>T1 : never + +type T2 = null & {}; +>T2 : never +>null : null + +type T3 = undefined & {}; +>T3 : never + +type T4 = null & undefined; +>T4 : never +>null : null + +type T6 = null & { a: string } & {}; +>T6 : never +>null : null +>a : string + +// Repro from #50519 + +type NonNullableNew = T & {}; +>NonNullableNew : NonNullableNew + +type NonNullableOld = T extends null | undefined ? never : T; +>NonNullableOld : NonNullableOld +>null : null + +type IsNullWithoutStrictNullChecks = NonNullableNew; +>IsNullWithoutStrictNullChecks : never +>null : null + +type IsAlwaysNever = NonNullableOld; +>IsAlwaysNever : never +>null : null + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports6.errors.txt b/tests/baselines/reference/allowSyntheticDefaultImports6.errors.txt index 916f50162a121..fedd9b350ff9f 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports6.errors.txt +++ b/tests/baselines/reference/allowSyntheticDefaultImports6.errors.txt @@ -11,6 +11,6 @@ tests/cases/compiler/a.ts(1,8): error TS1259: Module '"tests/cases/compiler/b"' import Foo from "./b"; ~~~ !!! error TS1259: Module '"tests/cases/compiler/b"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/b.d.ts:4:1: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/b.d.ts:4:1: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. export var x = new Foo(); \ No newline at end of file diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 4744d065a38ac..8003ac00a3c64 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -7033,7 +7033,6 @@ declare namespace ts.server { gc?(): void; trace?(s: string): void; require?(initialPath: string, moduleName: string): ModuleImportResult; - importServicePlugin?(root: string, moduleName: string): Promise; } } declare namespace ts.server { diff --git a/tests/baselines/reference/conditionalTypes2.errors.txt b/tests/baselines/reference/conditionalTypes2.errors.txt index a96ab6ac3a5d0..a96e6b907f749 100644 --- a/tests/baselines/reference/conditionalTypes2.errors.txt +++ b/tests/baselines/reference/conditionalTypes2.errors.txt @@ -32,7 +32,7 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(74,12): error TS2 Property 'bat' is missing in type 'Foo & Bar' but required in type '{ foo: string; bat: string; }'. tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2345: Argument of type 'Extract2' is not assignable to parameter of type '{ foo: string; bat: string; }'. Type 'T extends Bar ? T : never' is not assignable to type '{ foo: string; bat: string; }'. - Type 'Bar & Foo & T' is not assignable to type '{ foo: string; bat: string; }'. + Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'. ==== tests/cases/conformance/types/conditional/conditionalTypes2.ts (7 errors) ==== @@ -159,7 +159,8 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2 ~ !!! error TS2345: Argument of type 'Extract2' is not assignable to parameter of type '{ foo: string; bat: string; }'. !!! error TS2345: Type 'T extends Bar ? T : never' is not assignable to type '{ foo: string; bat: string; }'. -!!! error TS2345: Type 'Bar & Foo & T' is not assignable to type '{ foo: string; bat: string; }'. +!!! error TS2345: Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'. +!!! related TS2728 tests/cases/conformance/types/conditional/conditionalTypes2.ts:62:43: 'bat' is declared here. } // Repros from #22860 diff --git a/tests/baselines/reference/controlFlowGenericTypes.errors.txt b/tests/baselines/reference/controlFlowGenericTypes.errors.txt index 3130ba416fb75..b2f1de6b88dd6 100644 --- a/tests/baselines/reference/controlFlowGenericTypes.errors.txt +++ b/tests/baselines/reference/controlFlowGenericTypes.errors.txt @@ -240,4 +240,12 @@ tests/cases/conformance/controlFlow/controlFlowGenericTypes.ts(168,9): error TS2 control[key] = value; } } + + // Repro from #50465 + + type Column = (keyof T extends never ? { id?: number | string } : { id: T }) & { title?: string; } + + function getColumnProperty(column: Column, key: keyof Column) { + return column[key]; + } \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowGenericTypes.js b/tests/baselines/reference/controlFlowGenericTypes.js index a59b496ecd753..fbd4391269639 100644 --- a/tests/baselines/reference/controlFlowGenericTypes.js +++ b/tests/baselines/reference/controlFlowGenericTypes.js @@ -210,6 +210,14 @@ function update(control : T | undefined, k control[key] = value; } } + +// Repro from #50465 + +type Column = (keyof T extends never ? { id?: number | string } : { id: T }) & { title?: string; } + +function getColumnProperty(column: Column, key: keyof Column) { + return column[key]; +} //// [controlFlowGenericTypes.js] @@ -368,3 +376,6 @@ function update(control, key, value) { control[key] = value; } } +function getColumnProperty(column, key) { + return column[key]; +} diff --git a/tests/baselines/reference/controlFlowGenericTypes.symbols b/tests/baselines/reference/controlFlowGenericTypes.symbols index 1a1edf72f0afc..71b328efe87aa 100644 --- a/tests/baselines/reference/controlFlowGenericTypes.symbols +++ b/tests/baselines/reference/controlFlowGenericTypes.symbols @@ -626,3 +626,29 @@ function update(control : T | undefined, k } } +// Repro from #50465 + +type Column = (keyof T extends never ? { id?: number | string } : { id: T }) & { title?: string; } +>Column : Symbol(Column, Decl(controlFlowGenericTypes.ts, 210, 1)) +>T : Symbol(T, Decl(controlFlowGenericTypes.ts, 214, 12)) +>T : Symbol(T, Decl(controlFlowGenericTypes.ts, 214, 12)) +>id : Symbol(id, Decl(controlFlowGenericTypes.ts, 214, 43)) +>id : Symbol(id, Decl(controlFlowGenericTypes.ts, 214, 70)) +>T : Symbol(T, Decl(controlFlowGenericTypes.ts, 214, 12)) +>title : Symbol(title, Decl(controlFlowGenericTypes.ts, 214, 83)) + +function getColumnProperty(column: Column, key: keyof Column) { +>getColumnProperty : Symbol(getColumnProperty, Decl(controlFlowGenericTypes.ts, 214, 101)) +>T : Symbol(T, Decl(controlFlowGenericTypes.ts, 216, 27)) +>column : Symbol(column, Decl(controlFlowGenericTypes.ts, 216, 30)) +>Column : Symbol(Column, Decl(controlFlowGenericTypes.ts, 210, 1)) +>T : Symbol(T, Decl(controlFlowGenericTypes.ts, 216, 27)) +>key : Symbol(key, Decl(controlFlowGenericTypes.ts, 216, 48)) +>Column : Symbol(Column, Decl(controlFlowGenericTypes.ts, 210, 1)) +>T : Symbol(T, Decl(controlFlowGenericTypes.ts, 216, 27)) + + return column[key]; +>column : Symbol(column, Decl(controlFlowGenericTypes.ts, 216, 30)) +>key : Symbol(key, Decl(controlFlowGenericTypes.ts, 216, 48)) +} + diff --git a/tests/baselines/reference/controlFlowGenericTypes.types b/tests/baselines/reference/controlFlowGenericTypes.types index e6ebd4226b700..c02307a26e2a7 100644 --- a/tests/baselines/reference/controlFlowGenericTypes.types +++ b/tests/baselines/reference/controlFlowGenericTypes.types @@ -583,3 +583,22 @@ function update(control : T | undefined, k } } +// Repro from #50465 + +type Column = (keyof T extends never ? { id?: number | string } : { id: T }) & { title?: string; } +>Column : Column +>id : string | number | undefined +>id : T +>title : string | undefined + +function getColumnProperty(column: Column, key: keyof Column) { +>getColumnProperty : (column: Column, key: keyof Column) => Column["title" | keyof (keyof T extends never ? { id?: string | number | undefined; } : { id: T; })] +>column : Column +>key : "title" | keyof (keyof T extends never ? { id?: string | number | undefined; } : { id: T; }) + + return column[key]; +>column[key] : Column["title" | keyof (keyof T extends never ? { id?: string | number | undefined; } : { id: T; })] +>column : Column +>key : "title" | keyof (keyof T extends never ? { id?: string | number | undefined; } : { id: T; }) +} + diff --git a/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).js b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).js new file mode 100644 index 0000000000000..f543db3268926 --- /dev/null +++ b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).js @@ -0,0 +1,139 @@ +//// [emptyAnonymousObjectNarrowing.ts] +declare let nonNull: {}; +if (nonNull === "foo") { + nonNull; +} +else { + nonNull; +} + +declare let obj: { a: string }; +if (nonNull === obj) { + nonNull; +} +else { + nonNull; +} + +function f1(x: T) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} + +function f2(x: T) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} + +declare let union: "xyz" | { a: string } | undefined; +if (nonNull === union) { + nonNull; +} +else { + nonNull; +} + +if (nonNull === undefined) { + nonNull; +} +else { + nonNull; +} + +if (nonNull === null) { + nonNull; +} +else { + nonNull; +} + +if (nonNull == undefined) { + nonNull; +} +else { + nonNull; +} + +// Repro from #50567 +const foo = (value: unknown): string => { + if (!value) { + return 'foo'; + } + if (value === 'xyz') { + return value; // Type '{}' is not assignable to type 'string'. + } + return ''; +}; + + +//// [emptyAnonymousObjectNarrowing.js] +if (nonNull === "foo") { + nonNull; +} +else { + nonNull; +} +if (nonNull === obj) { + nonNull; +} +else { + nonNull; +} +function f1(x) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} +function f2(x) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} +if (nonNull === union) { + nonNull; +} +else { + nonNull; +} +if (nonNull === undefined) { + nonNull; +} +else { + nonNull; +} +if (nonNull === null) { + nonNull; +} +else { + nonNull; +} +if (nonNull == undefined) { + nonNull; +} +else { + nonNull; +} +// Repro from #50567 +var foo = function (value) { + if (!value) { + return 'foo'; + } + if (value === 'xyz') { + return value; // Type '{}' is not assignable to type 'string'. + } + return ''; +}; diff --git a/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).symbols b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).symbols new file mode 100644 index 0000000000000..1cf0efed0782d --- /dev/null +++ b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).symbols @@ -0,0 +1,139 @@ +=== tests/cases/compiler/emptyAnonymousObjectNarrowing.ts === +declare let nonNull: {}; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + +if (nonNull === "foo") { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +declare let obj: { a: string }; +>obj : Symbol(obj, Decl(emptyAnonymousObjectNarrowing.ts, 8, 11)) +>a : Symbol(a, Decl(emptyAnonymousObjectNarrowing.ts, 8, 18)) + +if (nonNull === obj) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>obj : Symbol(obj, Decl(emptyAnonymousObjectNarrowing.ts, 8, 11)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +function f1(x: T) { +>f1 : Symbol(f1, Decl(emptyAnonymousObjectNarrowing.ts, 14, 1)) +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 16, 12)) +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 16, 15)) +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 16, 12)) + + if (nonNull === x) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 16, 15)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + } + else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + } +} + +function f2(x: T) { +>f2 : Symbol(f2, Decl(emptyAnonymousObjectNarrowing.ts, 23, 1)) +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 25, 12)) +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 25, 30)) +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 25, 12)) + + if (nonNull === x) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 25, 30)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + } + else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + } +} + +declare let union: "xyz" | { a: string } | undefined; +>union : Symbol(union, Decl(emptyAnonymousObjectNarrowing.ts, 34, 11)) +>a : Symbol(a, Decl(emptyAnonymousObjectNarrowing.ts, 34, 28)) + +if (nonNull === union) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>union : Symbol(union, Decl(emptyAnonymousObjectNarrowing.ts, 34, 11)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +if (nonNull === undefined) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>undefined : Symbol(undefined) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +if (nonNull === null) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +if (nonNull == undefined) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>undefined : Symbol(undefined) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +// Repro from #50567 +const foo = (value: unknown): string => { +>foo : Symbol(foo, Decl(emptyAnonymousObjectNarrowing.ts, 64, 5)) +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) + + if (!value) { +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) + + return 'foo'; + } + if (value === 'xyz') { +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) + + return value; // Type '{}' is not assignable to type 'string'. +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) + } + return ''; +}; + diff --git a/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).types b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).types new file mode 100644 index 0000000000000..3ae0ad92788f1 --- /dev/null +++ b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).types @@ -0,0 +1,152 @@ +=== tests/cases/compiler/emptyAnonymousObjectNarrowing.ts === +declare let nonNull: {}; +>nonNull : {} + +if (nonNull === "foo") { +>nonNull === "foo" : boolean +>nonNull : {} +>"foo" : "foo" + + nonNull; +>nonNull : "foo" +} +else { + nonNull; +>nonNull : {} +} + +declare let obj: { a: string }; +>obj : { a: string; } +>a : string + +if (nonNull === obj) { +>nonNull === obj : boolean +>nonNull : {} +>obj : { a: string; } + + nonNull; +>nonNull : object +} +else { + nonNull; +>nonNull : {} +} + +function f1(x: T) { +>f1 : (x: T) => void +>x : T + + if (nonNull === x) { +>nonNull === x : boolean +>nonNull : {} +>x : T + + nonNull; +>nonNull : {} + } + else { + nonNull; +>nonNull : {} + } +} + +function f2(x: T) { +>f2 : (x: T) => void +>x : T + + if (nonNull === x) { +>nonNull === x : boolean +>nonNull : {} +>x : T + + nonNull; +>nonNull : {} + } + else { + nonNull; +>nonNull : {} + } +} + +declare let union: "xyz" | { a: string } | undefined; +>union : { a: string; } | "xyz" +>a : string + +if (nonNull === union) { +>nonNull === union : boolean +>nonNull : {} +>union : { a: string; } | "xyz" + + nonNull; +>nonNull : {} +} +else { + nonNull; +>nonNull : {} +} + +if (nonNull === undefined) { +>nonNull === undefined : boolean +>nonNull : {} +>undefined : undefined + + nonNull; +>nonNull : {} +} +else { + nonNull; +>nonNull : {} +} + +if (nonNull === null) { +>nonNull === null : boolean +>nonNull : {} +>null : null + + nonNull; +>nonNull : {} +} +else { + nonNull; +>nonNull : {} +} + +if (nonNull == undefined) { +>nonNull == undefined : boolean +>nonNull : {} +>undefined : undefined + + nonNull; +>nonNull : {} +} +else { + nonNull; +>nonNull : {} +} + +// Repro from #50567 +const foo = (value: unknown): string => { +>foo : (value: unknown) => string +>(value: unknown): string => { if (!value) { return 'foo'; } if (value === 'xyz') { return value; // Type '{}' is not assignable to type 'string'. } return '';} : (value: unknown) => string +>value : unknown + + if (!value) { +>!value : boolean +>value : unknown + + return 'foo'; +>'foo' : "foo" + } + if (value === 'xyz') { +>value === 'xyz' : boolean +>value : unknown +>'xyz' : "xyz" + + return value; // Type '{}' is not assignable to type 'string'. +>value : "xyz" + } + return ''; +>'' : "" + +}; + diff --git a/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=true).js b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=true).js new file mode 100644 index 0000000000000..f543db3268926 --- /dev/null +++ b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=true).js @@ -0,0 +1,139 @@ +//// [emptyAnonymousObjectNarrowing.ts] +declare let nonNull: {}; +if (nonNull === "foo") { + nonNull; +} +else { + nonNull; +} + +declare let obj: { a: string }; +if (nonNull === obj) { + nonNull; +} +else { + nonNull; +} + +function f1(x: T) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} + +function f2(x: T) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} + +declare let union: "xyz" | { a: string } | undefined; +if (nonNull === union) { + nonNull; +} +else { + nonNull; +} + +if (nonNull === undefined) { + nonNull; +} +else { + nonNull; +} + +if (nonNull === null) { + nonNull; +} +else { + nonNull; +} + +if (nonNull == undefined) { + nonNull; +} +else { + nonNull; +} + +// Repro from #50567 +const foo = (value: unknown): string => { + if (!value) { + return 'foo'; + } + if (value === 'xyz') { + return value; // Type '{}' is not assignable to type 'string'. + } + return ''; +}; + + +//// [emptyAnonymousObjectNarrowing.js] +if (nonNull === "foo") { + nonNull; +} +else { + nonNull; +} +if (nonNull === obj) { + nonNull; +} +else { + nonNull; +} +function f1(x) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} +function f2(x) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} +if (nonNull === union) { + nonNull; +} +else { + nonNull; +} +if (nonNull === undefined) { + nonNull; +} +else { + nonNull; +} +if (nonNull === null) { + nonNull; +} +else { + nonNull; +} +if (nonNull == undefined) { + nonNull; +} +else { + nonNull; +} +// Repro from #50567 +var foo = function (value) { + if (!value) { + return 'foo'; + } + if (value === 'xyz') { + return value; // Type '{}' is not assignable to type 'string'. + } + return ''; +}; diff --git a/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=true).symbols b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=true).symbols new file mode 100644 index 0000000000000..1cf0efed0782d --- /dev/null +++ b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=true).symbols @@ -0,0 +1,139 @@ +=== tests/cases/compiler/emptyAnonymousObjectNarrowing.ts === +declare let nonNull: {}; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + +if (nonNull === "foo") { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +declare let obj: { a: string }; +>obj : Symbol(obj, Decl(emptyAnonymousObjectNarrowing.ts, 8, 11)) +>a : Symbol(a, Decl(emptyAnonymousObjectNarrowing.ts, 8, 18)) + +if (nonNull === obj) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>obj : Symbol(obj, Decl(emptyAnonymousObjectNarrowing.ts, 8, 11)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +function f1(x: T) { +>f1 : Symbol(f1, Decl(emptyAnonymousObjectNarrowing.ts, 14, 1)) +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 16, 12)) +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 16, 15)) +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 16, 12)) + + if (nonNull === x) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 16, 15)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + } + else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + } +} + +function f2(x: T) { +>f2 : Symbol(f2, Decl(emptyAnonymousObjectNarrowing.ts, 23, 1)) +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 25, 12)) +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 25, 30)) +>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 25, 12)) + + if (nonNull === x) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 25, 30)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + } + else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + } +} + +declare let union: "xyz" | { a: string } | undefined; +>union : Symbol(union, Decl(emptyAnonymousObjectNarrowing.ts, 34, 11)) +>a : Symbol(a, Decl(emptyAnonymousObjectNarrowing.ts, 34, 28)) + +if (nonNull === union) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>union : Symbol(union, Decl(emptyAnonymousObjectNarrowing.ts, 34, 11)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +if (nonNull === undefined) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>undefined : Symbol(undefined) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +if (nonNull === null) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +if (nonNull == undefined) { +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +>undefined : Symbol(undefined) + + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} +else { + nonNull; +>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) +} + +// Repro from #50567 +const foo = (value: unknown): string => { +>foo : Symbol(foo, Decl(emptyAnonymousObjectNarrowing.ts, 64, 5)) +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) + + if (!value) { +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) + + return 'foo'; + } + if (value === 'xyz') { +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) + + return value; // Type '{}' is not assignable to type 'string'. +>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) + } + return ''; +}; + diff --git a/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=true).types b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=true).types new file mode 100644 index 0000000000000..621db01774a99 --- /dev/null +++ b/tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=true).types @@ -0,0 +1,152 @@ +=== tests/cases/compiler/emptyAnonymousObjectNarrowing.ts === +declare let nonNull: {}; +>nonNull : {} + +if (nonNull === "foo") { +>nonNull === "foo" : boolean +>nonNull : {} +>"foo" : "foo" + + nonNull; +>nonNull : "foo" +} +else { + nonNull; +>nonNull : {} +} + +declare let obj: { a: string }; +>obj : { a: string; } +>a : string + +if (nonNull === obj) { +>nonNull === obj : boolean +>nonNull : {} +>obj : { a: string; } + + nonNull; +>nonNull : object +} +else { + nonNull; +>nonNull : {} +} + +function f1(x: T) { +>f1 : (x: T) => void +>x : T + + if (nonNull === x) { +>nonNull === x : boolean +>nonNull : {} +>x : T + + nonNull; +>nonNull : {} + } + else { + nonNull; +>nonNull : {} + } +} + +function f2(x: T) { +>f2 : (x: T) => void +>x : T + + if (nonNull === x) { +>nonNull === x : boolean +>nonNull : {} +>x : T + + nonNull; +>nonNull : {} + } + else { + nonNull; +>nonNull : {} + } +} + +declare let union: "xyz" | { a: string } | undefined; +>union : { a: string; } | "xyz" | undefined +>a : string + +if (nonNull === union) { +>nonNull === union : boolean +>nonNull : {} +>union : { a: string; } | "xyz" | undefined + + nonNull; +>nonNull : {} +} +else { + nonNull; +>nonNull : {} +} + +if (nonNull === undefined) { +>nonNull === undefined : boolean +>nonNull : {} +>undefined : undefined + + nonNull; +>nonNull : never +} +else { + nonNull; +>nonNull : {} +} + +if (nonNull === null) { +>nonNull === null : boolean +>nonNull : {} +>null : null + + nonNull; +>nonNull : never +} +else { + nonNull; +>nonNull : {} +} + +if (nonNull == undefined) { +>nonNull == undefined : boolean +>nonNull : {} +>undefined : undefined + + nonNull; +>nonNull : never +} +else { + nonNull; +>nonNull : {} +} + +// Repro from #50567 +const foo = (value: unknown): string => { +>foo : (value: unknown) => string +>(value: unknown): string => { if (!value) { return 'foo'; } if (value === 'xyz') { return value; // Type '{}' is not assignable to type 'string'. } return '';} : (value: unknown) => string +>value : unknown + + if (!value) { +>!value : boolean +>value : unknown + + return 'foo'; +>'foo' : "foo" + } + if (value === 'xyz') { +>value === 'xyz' : boolean +>value : {} +>'xyz' : "xyz" + + return value; // Type '{}' is not assignable to type 'string'. +>value : "xyz" + } + return ''; +>'' : "" + +}; + diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index d7b992f2c1607..b1e3ac15f6b3b 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -77,43 +77,43 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses import x1 from "interface"; ~~ !!! error TS1259: Module '"interface"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:6:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:6:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. import x2 from "variable"; ~~ !!! error TS1259: Module '"variable"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:14:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:14:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. import x3 from "interface-variable"; ~~ !!! error TS1259: Module '"interface-variable"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:26:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:26:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. import x4 from "module"; ~~ !!! error TS1259: Module '"module"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:34:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:34:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. import x5 from "interface-module"; ~~ !!! error TS1259: Module '"interface-module"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:46:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:46:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. import x6 from "variable-module"; ~~ !!! error TS1259: Module '"variable-module"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:60:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:60:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. import x7 from "function"; ~~ !!! error TS1259: Module '"function"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:65:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:65:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. import x8 from "function-module"; ~~ !!! error TS1259: Module '"function-module"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:74:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:74:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. import x9 from "class"; ~~ !!! error TS1259: Module '"class"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:82:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:82:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. import x0 from "class-module"; ~~ !!! error TS1259: Module '"class-module"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/modules.d.ts:94:5: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 tests/cases/compiler/modules.d.ts:94:5: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. // namespace import import * as y1 from "interface"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt index 924792bf98adf..3eb6dd0e8b6c2 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt @@ -9,4 +9,4 @@ tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts(1,8): error TS1259: Modul import defaultBinding from "./es6ImportDefaultBindingInEs5_0"; ~~~~~~~~~~~~~~ !!! error TS1259: Module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts:2:1: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. \ No newline at end of file +!!! related TS2594 tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts:2:1: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. \ No newline at end of file diff --git a/tests/baselines/reference/esModuleInteropDefaultImports.errors.txt b/tests/baselines/reference/esModuleInteropDefaultImports.errors.txt new file mode 100644 index 0000000000000..f91da0382ed37 --- /dev/null +++ b/tests/baselines/reference/esModuleInteropDefaultImports.errors.txt @@ -0,0 +1,67 @@ +tests/cases/compiler/b.ts(15,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.ts(16,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.ts(17,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.ts(18,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.ts(19,6): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.ts(20,6): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + + +==== tests/cases/compiler/mod.ts (0 errors) ==== + declare function fun(): void; + export default fun; +==== tests/cases/compiler/a.ts (0 errors) ==== + import mod = require("./mod"); + export = mod; +==== tests/cases/compiler/b.ts (6 errors) ==== + import a from "./a"; + import { default as b } from "./a"; + import c, { default as d } from "./a"; + import * as self from "./b"; + export { default } from "./a"; + export { default as def } from "./a"; + + a === b; + b === c; + c === d; + d === self.default; + self.default === self.def; + + // should all fail + a(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + b(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + c(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + d(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + self.default(); + ~~~~~~~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + self.def(); + ~~~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + + // should all work + a.default(); + b.default(); + c.default(); + d.default(); + self.default.default(); + self.def.default(); \ No newline at end of file diff --git a/tests/baselines/reference/esModuleInteropDefaultImports.js b/tests/baselines/reference/esModuleInteropDefaultImports.js new file mode 100644 index 0000000000000..f893e0e968b99 --- /dev/null +++ b/tests/baselines/reference/esModuleInteropDefaultImports.js @@ -0,0 +1,103 @@ +//// [tests/cases/compiler/esModuleInteropDefaultImports.ts] //// + +//// [mod.ts] +declare function fun(): void; +export default fun; +//// [a.ts] +import mod = require("./mod"); +export = mod; +//// [b.ts] +import a from "./a"; +import { default as b } from "./a"; +import c, { default as d } from "./a"; +import * as self from "./b"; +export { default } from "./a"; +export { default as def } from "./a"; + +a === b; +b === c; +c === d; +d === self.default; +self.default === self.def; + +// should all fail +a(); +b(); +c(); +d(); +self.default(); +self.def(); + +// should all work +a.default(); +b.default(); +c.default(); +d.default(); +self.default.default(); +self.def.default(); + +//// [mod.js] +"use strict"; +exports.__esModule = true; +exports["default"] = fun; +//// [a.js] +"use strict"; +var mod = require("./mod"); +module.exports = mod; +//// [b.js] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +exports.__esModule = true; +exports.def = exports["default"] = void 0; +var a_1 = __importDefault(require("./a")); +var a_2 = __importDefault(require("./a")); +var a_3 = __importDefault(require("./a")); +var self = __importStar(require("./b")); +var a_4 = require("./a"); +__createBinding(exports, a_4, "default"); +var a_5 = require("./a"); +__createBinding(exports, a_5, "default", "def"); +a_1["default"] === a_2["default"]; +a_2["default"] === a_3["default"]; +a_3["default"] === a_3["default"]; +a_3["default"] === self["default"]; +self["default"] === self.def; +// should all fail +(0, a_1["default"])(); +(0, a_2["default"])(); +(0, a_3["default"])(); +(0, a_3["default"])(); +self["default"](); +self.def(); +// should all work +a_1["default"]["default"](); +a_2["default"]["default"](); +a_3["default"]["default"](); +a_3["default"]["default"](); +self["default"]["default"](); +self.def["default"](); diff --git a/tests/baselines/reference/esModuleInteropDefaultImports.symbols b/tests/baselines/reference/esModuleInteropDefaultImports.symbols new file mode 100644 index 0000000000000..05c18c13e4cfb --- /dev/null +++ b/tests/baselines/reference/esModuleInteropDefaultImports.symbols @@ -0,0 +1,121 @@ +=== tests/cases/compiler/mod.ts === +declare function fun(): void; +>fun : Symbol(fun, Decl(mod.ts, 0, 0)) + +export default fun; +>fun : Symbol(fun, Decl(mod.ts, 0, 0)) + +=== tests/cases/compiler/a.ts === +import mod = require("./mod"); +>mod : Symbol(mod, Decl(a.ts, 0, 0)) + +export = mod; +>mod : Symbol(mod, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +import a from "./a"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +import { default as b } from "./a"; +>default : Symbol(mod, Decl(a.ts, 0, 30)) +>b : Symbol(b, Decl(b.ts, 1, 8)) + +import c, { default as d } from "./a"; +>c : Symbol(c, Decl(b.ts, 2, 6)) +>default : Symbol(mod, Decl(a.ts, 0, 30)) +>d : Symbol(d, Decl(b.ts, 2, 11)) + +import * as self from "./b"; +>self : Symbol(self, Decl(b.ts, 3, 6)) + +export { default } from "./a"; +>default : Symbol(self.default, Decl(b.ts, 4, 8)) + +export { default as def } from "./a"; +>default : Symbol(mod, Decl(a.ts, 0, 30)) +>def : Symbol(self.def, Decl(b.ts, 5, 8)) + +a === b; +>a : Symbol(a, Decl(b.ts, 0, 6)) +>b : Symbol(b, Decl(b.ts, 1, 8)) + +b === c; +>b : Symbol(b, Decl(b.ts, 1, 8)) +>c : Symbol(c, Decl(b.ts, 2, 6)) + +c === d; +>c : Symbol(c, Decl(b.ts, 2, 6)) +>d : Symbol(d, Decl(b.ts, 2, 11)) + +d === self.default; +>d : Symbol(d, Decl(b.ts, 2, 11)) +>self.default : Symbol(self.default, Decl(b.ts, 4, 8)) +>self : Symbol(self, Decl(b.ts, 3, 6)) +>default : Symbol(self.default, Decl(b.ts, 4, 8)) + +self.default === self.def; +>self.default : Symbol(self.default, Decl(b.ts, 4, 8)) +>self : Symbol(self, Decl(b.ts, 3, 6)) +>default : Symbol(self.default, Decl(b.ts, 4, 8)) +>self.def : Symbol(self.def, Decl(b.ts, 5, 8)) +>self : Symbol(self, Decl(b.ts, 3, 6)) +>def : Symbol(self.def, Decl(b.ts, 5, 8)) + +// should all fail +a(); +>a : Symbol(a, Decl(b.ts, 0, 6)) + +b(); +>b : Symbol(b, Decl(b.ts, 1, 8)) + +c(); +>c : Symbol(c, Decl(b.ts, 2, 6)) + +d(); +>d : Symbol(d, Decl(b.ts, 2, 11)) + +self.default(); +>self.default : Symbol(self.default, Decl(b.ts, 4, 8)) +>self : Symbol(self, Decl(b.ts, 3, 6)) +>default : Symbol(self.default, Decl(b.ts, 4, 8)) + +self.def(); +>self.def : Symbol(self.def, Decl(b.ts, 5, 8)) +>self : Symbol(self, Decl(b.ts, 3, 6)) +>def : Symbol(self.def, Decl(b.ts, 5, 8)) + +// should all work +a.default(); +>a.default : Symbol(a.default, Decl(mod.ts, 0, 29)) +>a : Symbol(a, Decl(b.ts, 0, 6)) +>default : Symbol(a.default, Decl(mod.ts, 0, 29)) + +b.default(); +>b.default : Symbol(a.default, Decl(mod.ts, 0, 29)) +>b : Symbol(b, Decl(b.ts, 1, 8)) +>default : Symbol(a.default, Decl(mod.ts, 0, 29)) + +c.default(); +>c.default : Symbol(a.default, Decl(mod.ts, 0, 29)) +>c : Symbol(c, Decl(b.ts, 2, 6)) +>default : Symbol(a.default, Decl(mod.ts, 0, 29)) + +d.default(); +>d.default : Symbol(a.default, Decl(mod.ts, 0, 29)) +>d : Symbol(d, Decl(b.ts, 2, 11)) +>default : Symbol(a.default, Decl(mod.ts, 0, 29)) + +self.default.default(); +>self.default.default : Symbol(a.default, Decl(mod.ts, 0, 29)) +>self.default : Symbol(self.default, Decl(b.ts, 4, 8)) +>self : Symbol(self, Decl(b.ts, 3, 6)) +>default : Symbol(self.default, Decl(b.ts, 4, 8)) +>default : Symbol(a.default, Decl(mod.ts, 0, 29)) + +self.def.default(); +>self.def.default : Symbol(a.default, Decl(mod.ts, 0, 29)) +>self.def : Symbol(self.def, Decl(b.ts, 5, 8)) +>self : Symbol(self, Decl(b.ts, 3, 6)) +>def : Symbol(self.def, Decl(b.ts, 5, 8)) +>default : Symbol(a.default, Decl(mod.ts, 0, 29)) + diff --git a/tests/baselines/reference/esModuleInteropDefaultImports.types b/tests/baselines/reference/esModuleInteropDefaultImports.types new file mode 100644 index 0000000000000..961e7063b2f9e --- /dev/null +++ b/tests/baselines/reference/esModuleInteropDefaultImports.types @@ -0,0 +1,138 @@ +=== tests/cases/compiler/mod.ts === +declare function fun(): void; +>fun : () => void + +export default fun; +>fun : () => void + +=== tests/cases/compiler/a.ts === +import mod = require("./mod"); +>mod : typeof mod + +export = mod; +>mod : typeof mod + +=== tests/cases/compiler/b.ts === +import a from "./a"; +>a : typeof a + +import { default as b } from "./a"; +>default : typeof a +>b : typeof a + +import c, { default as d } from "./a"; +>c : typeof a +>default : typeof a +>d : typeof a + +import * as self from "./b"; +>self : typeof self + +export { default } from "./a"; +>default : typeof a + +export { default as def } from "./a"; +>default : typeof a +>def : typeof a + +a === b; +>a === b : boolean +>a : typeof a +>b : typeof a + +b === c; +>b === c : boolean +>b : typeof a +>c : typeof a + +c === d; +>c === d : boolean +>c : typeof a +>d : typeof a + +d === self.default; +>d === self.default : boolean +>d : typeof a +>self.default : typeof a +>self : typeof self +>default : typeof a + +self.default === self.def; +>self.default === self.def : boolean +>self.default : typeof a +>self : typeof self +>default : typeof a +>self.def : typeof a +>self : typeof self +>def : typeof a + +// should all fail +a(); +>a() : any +>a : typeof a + +b(); +>b() : any +>b : typeof a + +c(); +>c() : any +>c : typeof a + +d(); +>d() : any +>d : typeof a + +self.default(); +>self.default() : any +>self.default : typeof a +>self : typeof self +>default : typeof a + +self.def(); +>self.def() : any +>self.def : typeof a +>self : typeof self +>def : typeof a + +// should all work +a.default(); +>a.default() : void +>a.default : () => void +>a : typeof a +>default : () => void + +b.default(); +>b.default() : void +>b.default : () => void +>b : typeof a +>default : () => void + +c.default(); +>c.default() : void +>c.default : () => void +>c : typeof a +>default : () => void + +d.default(); +>d.default() : void +>d.default : () => void +>d : typeof a +>default : () => void + +self.default.default(); +>self.default.default() : void +>self.default.default : () => void +>self.default : typeof a +>self : typeof self +>default : typeof a +>default : () => void + +self.def.default(); +>self.def.default() : void +>self.def.default : () => void +>self.def : typeof a +>self : typeof self +>def : typeof a +>default : () => void + diff --git a/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.js b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.js new file mode 100644 index 0000000000000..971053105ca0a --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.js @@ -0,0 +1,10 @@ +//// [excessPropertyCheckingIntersectionWithConditional.ts] +type Foo = K extends unknown ? { a: number } : unknown +const createDefaultExample = (x: K): Foo & { x: K; } => { + return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2 +} + +//// [excessPropertyCheckingIntersectionWithConditional.js] +var createDefaultExample = function (x) { + return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2 +}; diff --git a/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.symbols b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.symbols new file mode 100644 index 0000000000000..aca3252c77402 --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts === +type Foo = K extends unknown ? { a: number } : unknown +>Foo : Symbol(Foo, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 0)) +>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 9)) +>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 9)) +>a : Symbol(a, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 35)) + +const createDefaultExample = (x: K): Foo & { x: K; } => { +>createDefaultExample : Symbol(createDefaultExample, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 5)) +>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 30)) +>x : Symbol(x, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 34)) +>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 30)) +>Foo : Symbol(Foo, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 0, 0)) +>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 30)) +>x : Symbol(x, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 51)) +>K : Symbol(K, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 30)) + + return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2 +>a : Symbol(a, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 2, 10)) +>x : Symbol(x, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 2, 16)) +>x : Symbol(x, Decl(excessPropertyCheckingIntersectionWithConditional.ts, 1, 34)) +} diff --git a/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.types b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.types new file mode 100644 index 0000000000000..5d2ec637e8da2 --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckingIntersectionWithConditional.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts === +type Foo = K extends unknown ? { a: number } : unknown +>Foo : Foo +>a : number + +const createDefaultExample = (x: K): Foo & { x: K; } => { +>createDefaultExample : (x: K) => Foo & { x: K; } +>(x: K): Foo & { x: K; } => { return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2} : (x: K) => Foo & { x: K; } +>x : K +>x : K + + return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2 +>{ a: 1, x: x } : { a: number; x: K; } +>a : number +>1 : 1 +>x : K +>x : K +} diff --git a/tests/baselines/reference/exportAssignmentWithoutAllowSyntheticDefaultImportsError.errors.txt b/tests/baselines/reference/exportAssignmentWithoutAllowSyntheticDefaultImportsError.errors.txt index d59ec8b42c86f..ba44def77ef37 100644 --- a/tests/baselines/reference/exportAssignmentWithoutAllowSyntheticDefaultImportsError.errors.txt +++ b/tests/baselines/reference/exportAssignmentWithoutAllowSyntheticDefaultImportsError.errors.txt @@ -12,4 +12,4 @@ import bar from './bar'; ~~~ !!! error TS1259: Module '"/bar"' can only be default-imported using the 'allowSyntheticDefaultImports' flag -!!! related TS2594 /bar.ts:1:1: This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. \ No newline at end of file +!!! related TS2594 /bar.ts:1:1: This module is declared with 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. \ No newline at end of file diff --git a/tests/baselines/reference/inKeywordAndUnknown.js b/tests/baselines/reference/inKeywordAndUnknown.js new file mode 100644 index 0000000000000..354bb8c4b1884 --- /dev/null +++ b/tests/baselines/reference/inKeywordAndUnknown.js @@ -0,0 +1,36 @@ +//// [inKeywordAndUnknown.ts] +// Repro from #50531 + +function f(x: {}, y: unknown) { + if (!("a" in x)) { + return; + } + x; // {} + if (!y) { + return; + } + y; // {} + if (!("a" in y)) { + return; + } + y; // {} +} + + +//// [inKeywordAndUnknown.js] +"use strict"; +// Repro from #50531 +function f(x, y) { + if (!("a" in x)) { + return; + } + x; // {} + if (!y) { + return; + } + y; // {} + if (!("a" in y)) { + return; + } + y; // {} +} diff --git a/tests/baselines/reference/inKeywordAndUnknown.symbols b/tests/baselines/reference/inKeywordAndUnknown.symbols new file mode 100644 index 0000000000000..145e92dc7f657 --- /dev/null +++ b/tests/baselines/reference/inKeywordAndUnknown.symbols @@ -0,0 +1,33 @@ +=== tests/cases/compiler/inKeywordAndUnknown.ts === +// Repro from #50531 + +function f(x: {}, y: unknown) { +>f : Symbol(f, Decl(inKeywordAndUnknown.ts, 0, 0)) +>x : Symbol(x, Decl(inKeywordAndUnknown.ts, 2, 11)) +>y : Symbol(y, Decl(inKeywordAndUnknown.ts, 2, 17)) + + if (!("a" in x)) { +>x : Symbol(x, Decl(inKeywordAndUnknown.ts, 2, 11)) + + return; + } + x; // {} +>x : Symbol(x, Decl(inKeywordAndUnknown.ts, 2, 11)) + + if (!y) { +>y : Symbol(y, Decl(inKeywordAndUnknown.ts, 2, 17)) + + return; + } + y; // {} +>y : Symbol(y, Decl(inKeywordAndUnknown.ts, 2, 17)) + + if (!("a" in y)) { +>y : Symbol(y, Decl(inKeywordAndUnknown.ts, 2, 17)) + + return; + } + y; // {} +>y : Symbol(y, Decl(inKeywordAndUnknown.ts, 2, 17)) +} + diff --git a/tests/baselines/reference/inKeywordAndUnknown.types b/tests/baselines/reference/inKeywordAndUnknown.types new file mode 100644 index 0000000000000..74345ca004547 --- /dev/null +++ b/tests/baselines/reference/inKeywordAndUnknown.types @@ -0,0 +1,42 @@ +=== tests/cases/compiler/inKeywordAndUnknown.ts === +// Repro from #50531 + +function f(x: {}, y: unknown) { +>f : (x: {}, y: unknown) => void +>x : {} +>y : unknown + + if (!("a" in x)) { +>!("a" in x) : boolean +>("a" in x) : boolean +>"a" in x : boolean +>"a" : "a" +>x : {} + + return; + } + x; // {} +>x : {} + + if (!y) { +>!y : boolean +>y : unknown + + return; + } + y; // {} +>y : {} + + if (!("a" in y)) { +>!("a" in y) : boolean +>("a" in y) : boolean +>"a" in y : boolean +>"a" : "a" +>y : {} + + return; + } + y; // {} +>y : {} +} + diff --git a/tests/baselines/reference/javascriptImportDefaultBadExport.errors.txt b/tests/baselines/reference/javascriptImportDefaultBadExport.errors.txt index 71ff85e2155fe..e5631c22a89ed 100644 --- a/tests/baselines/reference/javascriptImportDefaultBadExport.errors.txt +++ b/tests/baselines/reference/javascriptImportDefaultBadExport.errors.txt @@ -12,5 +12,5 @@ import a from "./a"; ~ !!! error TS1259: Module '"/a"' can only be default-imported using the 'esModuleInterop' flag -!!! related TS2594 /a.js:5:1: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. +!!! related TS2594 /a.js:5:1: This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. \ No newline at end of file diff --git a/tests/baselines/reference/jsxIntrinsicElementsCompatability.js b/tests/baselines/reference/jsxIntrinsicElementsCompatability.js new file mode 100644 index 0000000000000..4381071491dba --- /dev/null +++ b/tests/baselines/reference/jsxIntrinsicElementsCompatability.js @@ -0,0 +1,24 @@ +//// [jsxIntrinsicElementsCompatability.tsx] +/// +import * as React from "react"; +function SomeComponent(props: { element?: T } & JSX.IntrinsicElements[T]): JSX.Element { + // Just so the return value is RectElement, the rendered element doesnt matter + return
+} + +function Test(el: T) { + return +} + +//// [jsxIntrinsicElementsCompatability.js] +"use strict"; +exports.__esModule = true; +/// +var React = require("react"); +function SomeComponent(props) { + // Just so the return value is RectElement, the rendered element doesnt matter + return React.createElement("div", null); +} +function Test(el) { + return React.createElement(SomeComponent, { element: el }); +} diff --git a/tests/baselines/reference/jsxIntrinsicElementsCompatability.symbols b/tests/baselines/reference/jsxIntrinsicElementsCompatability.symbols new file mode 100644 index 0000000000000..86da5d624acd1 --- /dev/null +++ b/tests/baselines/reference/jsxIntrinsicElementsCompatability.symbols @@ -0,0 +1,33 @@ +=== tests/cases/compiler/jsxIntrinsicElementsCompatability.tsx === +/// +import * as React from "react"; +>React : Symbol(React, Decl(jsxIntrinsicElementsCompatability.tsx, 1, 6)) + +function SomeComponent(props: { element?: T } & JSX.IntrinsicElements[T]): JSX.Element { +>SomeComponent : Symbol(SomeComponent, Decl(jsxIntrinsicElementsCompatability.tsx, 1, 31)) +>T : Symbol(T, Decl(jsxIntrinsicElementsCompatability.tsx, 2, 23)) +>props : Symbol(props, Decl(jsxIntrinsicElementsCompatability.tsx, 2, 49)) +>element : Symbol(element, Decl(jsxIntrinsicElementsCompatability.tsx, 2, 57)) +>T : Symbol(T, Decl(jsxIntrinsicElementsCompatability.tsx, 2, 23)) +>JSX : Symbol(JSX, Decl(react16.d.ts, 2493, 12)) +>IntrinsicElements : Symbol(JSX.IntrinsicElements, Decl(react16.d.ts, 2514, 86)) +>T : Symbol(T, Decl(jsxIntrinsicElementsCompatability.tsx, 2, 23)) +>JSX : Symbol(JSX, Decl(react16.d.ts, 2493, 12)) +>Element : Symbol(JSX.Element, Decl(react16.d.ts, 2494, 23)) + + // Just so the return value is RectElement, the rendered element doesnt matter + return
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114)) +} + +function Test(el: T) { +>Test : Symbol(Test, Decl(jsxIntrinsicElementsCompatability.tsx, 5, 1)) +>T : Symbol(T, Decl(jsxIntrinsicElementsCompatability.tsx, 7, 14)) +>el : Symbol(el, Decl(jsxIntrinsicElementsCompatability.tsx, 7, 40)) +>T : Symbol(T, Decl(jsxIntrinsicElementsCompatability.tsx, 7, 14)) + + return +>SomeComponent : Symbol(SomeComponent, Decl(jsxIntrinsicElementsCompatability.tsx, 1, 31)) +>element : Symbol(element, Decl(jsxIntrinsicElementsCompatability.tsx, 8, 25)) +>el : Symbol(el, Decl(jsxIntrinsicElementsCompatability.tsx, 7, 40)) +} diff --git a/tests/baselines/reference/jsxIntrinsicElementsCompatability.types b/tests/baselines/reference/jsxIntrinsicElementsCompatability.types new file mode 100644 index 0000000000000..e0479dae19e78 --- /dev/null +++ b/tests/baselines/reference/jsxIntrinsicElementsCompatability.types @@ -0,0 +1,28 @@ +=== tests/cases/compiler/jsxIntrinsicElementsCompatability.tsx === +/// +import * as React from "react"; +>React : typeof React + +function SomeComponent(props: { element?: T } & JSX.IntrinsicElements[T]): JSX.Element { +>SomeComponent : (props: { element?: T;} & JSX.IntrinsicElements[T]) => JSX.Element +>props : { element?: T | undefined; } & JSX.IntrinsicElements[T] +>element : T | undefined +>JSX : any +>JSX : any + + // Just so the return value is RectElement, the rendered element doesnt matter + return
+>
: JSX.Element +>div : any +} + +function Test(el: T) { +>Test : (el: T) => JSX.Element +>el : T + + return +> : JSX.Element +>SomeComponent : (props: { element?: T | undefined; } & JSX.IntrinsicElements[T]) => JSX.Element +>element : T +>el : T +} diff --git a/tests/baselines/reference/moduleNodeDefaultImports(module=node16).errors.txt b/tests/baselines/reference/moduleNodeDefaultImports(module=node16).errors.txt new file mode 100644 index 0000000000000..f90724d92338b --- /dev/null +++ b/tests/baselines/reference/moduleNodeDefaultImports(module=node16).errors.txt @@ -0,0 +1,64 @@ +tests/cases/compiler/b.mts(15,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(16,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(17,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(18,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(19,6): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(20,6): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + + +==== tests/cases/compiler/mod.cts (0 errors) ==== + declare function fun(): void; + export default fun; +==== tests/cases/compiler/b.mts (6 errors) ==== + import a from "./mod.cjs"; + import { default as b } from "./mod.cjs"; + import c, { default as d } from "./mod.cjs"; + import * as self from "./b.mjs"; + export { default } from "./mod.cjs"; + export { default as def } from "./mod.cjs"; + + a === b; + b === c; + c === d; + d === self.default; + self.default === self.def; + + // should all fail + a(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + b(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + c(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + d(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + self.default(); + ~~~~~~~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + self.def(); + ~~~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + + // should all work + a.default(); + b.default(); + c.default(); + d.default(); + self.default.default(); + self.def.default(); \ No newline at end of file diff --git a/tests/baselines/reference/moduleNodeDefaultImports(module=node16).js b/tests/baselines/reference/moduleNodeDefaultImports(module=node16).js new file mode 100644 index 0000000000000..1d6e31ec0afb2 --- /dev/null +++ b/tests/baselines/reference/moduleNodeDefaultImports(module=node16).js @@ -0,0 +1,65 @@ +//// [tests/cases/compiler/moduleNodeDefaultImports.ts] //// + +//// [mod.cts] +declare function fun(): void; +export default fun; +//// [b.mts] +import a from "./mod.cjs"; +import { default as b } from "./mod.cjs"; +import c, { default as d } from "./mod.cjs"; +import * as self from "./b.mjs"; +export { default } from "./mod.cjs"; +export { default as def } from "./mod.cjs"; + +a === b; +b === c; +c === d; +d === self.default; +self.default === self.def; + +// should all fail +a(); +b(); +c(); +d(); +self.default(); +self.def(); + +// should all work +a.default(); +b.default(); +c.default(); +d.default(); +self.default.default(); +self.def.default(); + +//// [mod.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = fun; +//// [b.mjs] +import a from "./mod.cjs"; +import { default as b } from "./mod.cjs"; +import c, { default as d } from "./mod.cjs"; +import * as self from "./b.mjs"; +export { default } from "./mod.cjs"; +export { default as def } from "./mod.cjs"; +a === b; +b === c; +c === d; +d === self.default; +self.default === self.def; +// should all fail +a(); +b(); +c(); +d(); +self.default(); +self.def(); +// should all work +a.default(); +b.default(); +c.default(); +d.default(); +self.default.default(); +self.def.default(); diff --git a/tests/baselines/reference/moduleNodeDefaultImports(module=node16).symbols b/tests/baselines/reference/moduleNodeDefaultImports(module=node16).symbols new file mode 100644 index 0000000000000..7d475bb0e7e6a --- /dev/null +++ b/tests/baselines/reference/moduleNodeDefaultImports(module=node16).symbols @@ -0,0 +1,114 @@ +=== tests/cases/compiler/mod.cts === +declare function fun(): void; +>fun : Symbol(fun, Decl(mod.cts, 0, 0)) + +export default fun; +>fun : Symbol(fun, Decl(mod.cts, 0, 0)) + +=== tests/cases/compiler/b.mts === +import a from "./mod.cjs"; +>a : Symbol(a, Decl(b.mts, 0, 6)) + +import { default as b } from "./mod.cjs"; +>default : Symbol(a, Decl(mod.cts, 0, 0)) +>b : Symbol(b, Decl(b.mts, 1, 8)) + +import c, { default as d } from "./mod.cjs"; +>c : Symbol(c, Decl(b.mts, 2, 6)) +>default : Symbol(a, Decl(mod.cts, 0, 0)) +>d : Symbol(d, Decl(b.mts, 2, 11)) + +import * as self from "./b.mjs"; +>self : Symbol(self, Decl(b.mts, 3, 6)) + +export { default } from "./mod.cjs"; +>default : Symbol(self.default, Decl(b.mts, 4, 8)) + +export { default as def } from "./mod.cjs"; +>default : Symbol(a, Decl(mod.cts, 0, 0)) +>def : Symbol(self.def, Decl(b.mts, 5, 8)) + +a === b; +>a : Symbol(a, Decl(b.mts, 0, 6)) +>b : Symbol(b, Decl(b.mts, 1, 8)) + +b === c; +>b : Symbol(b, Decl(b.mts, 1, 8)) +>c : Symbol(c, Decl(b.mts, 2, 6)) + +c === d; +>c : Symbol(c, Decl(b.mts, 2, 6)) +>d : Symbol(d, Decl(b.mts, 2, 11)) + +d === self.default; +>d : Symbol(d, Decl(b.mts, 2, 11)) +>self.default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>default : Symbol(self.default, Decl(b.mts, 4, 8)) + +self.default === self.def; +>self.default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self.def : Symbol(self.def, Decl(b.mts, 5, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>def : Symbol(self.def, Decl(b.mts, 5, 8)) + +// should all fail +a(); +>a : Symbol(a, Decl(b.mts, 0, 6)) + +b(); +>b : Symbol(b, Decl(b.mts, 1, 8)) + +c(); +>c : Symbol(c, Decl(b.mts, 2, 6)) + +d(); +>d : Symbol(d, Decl(b.mts, 2, 11)) + +self.default(); +>self.default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>default : Symbol(self.default, Decl(b.mts, 4, 8)) + +self.def(); +>self.def : Symbol(self.def, Decl(b.mts, 5, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>def : Symbol(self.def, Decl(b.mts, 5, 8)) + +// should all work +a.default(); +>a.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>a : Symbol(a, Decl(b.mts, 0, 6)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +b.default(); +>b.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>b : Symbol(b, Decl(b.mts, 1, 8)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +c.default(); +>c.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>c : Symbol(c, Decl(b.mts, 2, 6)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +d.default(); +>d.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>d : Symbol(d, Decl(b.mts, 2, 11)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +self.default.default(); +>self.default.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>self.default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>default : Symbol(self.default, Decl(b.mts, 4, 8)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +self.def.default(); +>self.def.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>self.def : Symbol(self.def, Decl(b.mts, 5, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>def : Symbol(self.def, Decl(b.mts, 5, 8)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + diff --git a/tests/baselines/reference/moduleNodeDefaultImports(module=node16).types b/tests/baselines/reference/moduleNodeDefaultImports(module=node16).types new file mode 100644 index 0000000000000..653dac121b8b0 --- /dev/null +++ b/tests/baselines/reference/moduleNodeDefaultImports(module=node16).types @@ -0,0 +1,131 @@ +=== tests/cases/compiler/mod.cts === +declare function fun(): void; +>fun : () => void + +export default fun; +>fun : () => void + +=== tests/cases/compiler/b.mts === +import a from "./mod.cjs"; +>a : typeof a + +import { default as b } from "./mod.cjs"; +>default : typeof a +>b : typeof a + +import c, { default as d } from "./mod.cjs"; +>c : typeof a +>default : typeof a +>d : typeof a + +import * as self from "./b.mjs"; +>self : typeof self + +export { default } from "./mod.cjs"; +>default : typeof a + +export { default as def } from "./mod.cjs"; +>default : typeof a +>def : typeof a + +a === b; +>a === b : boolean +>a : typeof a +>b : typeof a + +b === c; +>b === c : boolean +>b : typeof a +>c : typeof a + +c === d; +>c === d : boolean +>c : typeof a +>d : typeof a + +d === self.default; +>d === self.default : boolean +>d : typeof a +>self.default : typeof a +>self : typeof self +>default : typeof a + +self.default === self.def; +>self.default === self.def : boolean +>self.default : typeof a +>self : typeof self +>default : typeof a +>self.def : typeof a +>self : typeof self +>def : typeof a + +// should all fail +a(); +>a() : any +>a : typeof a + +b(); +>b() : any +>b : typeof a + +c(); +>c() : any +>c : typeof a + +d(); +>d() : any +>d : typeof a + +self.default(); +>self.default() : any +>self.default : typeof a +>self : typeof self +>default : typeof a + +self.def(); +>self.def() : any +>self.def : typeof a +>self : typeof self +>def : typeof a + +// should all work +a.default(); +>a.default() : void +>a.default : () => void +>a : typeof a +>default : () => void + +b.default(); +>b.default() : void +>b.default : () => void +>b : typeof a +>default : () => void + +c.default(); +>c.default() : void +>c.default : () => void +>c : typeof a +>default : () => void + +d.default(); +>d.default() : void +>d.default : () => void +>d : typeof a +>default : () => void + +self.default.default(); +>self.default.default() : void +>self.default.default : () => void +>self.default : typeof a +>self : typeof self +>default : typeof a +>default : () => void + +self.def.default(); +>self.def.default() : void +>self.def.default : () => void +>self.def : typeof a +>self : typeof self +>def : typeof a +>default : () => void + diff --git a/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).errors.txt b/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..f90724d92338b --- /dev/null +++ b/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).errors.txt @@ -0,0 +1,64 @@ +tests/cases/compiler/b.mts(15,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(16,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(17,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(18,1): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(19,6): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. +tests/cases/compiler/b.mts(20,6): error TS2349: This expression is not callable. + Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + + +==== tests/cases/compiler/mod.cts (0 errors) ==== + declare function fun(): void; + export default fun; +==== tests/cases/compiler/b.mts (6 errors) ==== + import a from "./mod.cjs"; + import { default as b } from "./mod.cjs"; + import c, { default as d } from "./mod.cjs"; + import * as self from "./b.mjs"; + export { default } from "./mod.cjs"; + export { default as def } from "./mod.cjs"; + + a === b; + b === c; + c === d; + d === self.default; + self.default === self.def; + + // should all fail + a(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + b(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + c(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + d(); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + self.default(); + ~~~~~~~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + self.def(); + ~~~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'typeof import("tests/cases/compiler/mod")' has no call signatures. + + // should all work + a.default(); + b.default(); + c.default(); + d.default(); + self.default.default(); + self.def.default(); \ No newline at end of file diff --git a/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).js b/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).js new file mode 100644 index 0000000000000..1d6e31ec0afb2 --- /dev/null +++ b/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).js @@ -0,0 +1,65 @@ +//// [tests/cases/compiler/moduleNodeDefaultImports.ts] //// + +//// [mod.cts] +declare function fun(): void; +export default fun; +//// [b.mts] +import a from "./mod.cjs"; +import { default as b } from "./mod.cjs"; +import c, { default as d } from "./mod.cjs"; +import * as self from "./b.mjs"; +export { default } from "./mod.cjs"; +export { default as def } from "./mod.cjs"; + +a === b; +b === c; +c === d; +d === self.default; +self.default === self.def; + +// should all fail +a(); +b(); +c(); +d(); +self.default(); +self.def(); + +// should all work +a.default(); +b.default(); +c.default(); +d.default(); +self.default.default(); +self.def.default(); + +//// [mod.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = fun; +//// [b.mjs] +import a from "./mod.cjs"; +import { default as b } from "./mod.cjs"; +import c, { default as d } from "./mod.cjs"; +import * as self from "./b.mjs"; +export { default } from "./mod.cjs"; +export { default as def } from "./mod.cjs"; +a === b; +b === c; +c === d; +d === self.default; +self.default === self.def; +// should all fail +a(); +b(); +c(); +d(); +self.default(); +self.def(); +// should all work +a.default(); +b.default(); +c.default(); +d.default(); +self.default.default(); +self.def.default(); diff --git a/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).symbols b/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).symbols new file mode 100644 index 0000000000000..7d475bb0e7e6a --- /dev/null +++ b/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).symbols @@ -0,0 +1,114 @@ +=== tests/cases/compiler/mod.cts === +declare function fun(): void; +>fun : Symbol(fun, Decl(mod.cts, 0, 0)) + +export default fun; +>fun : Symbol(fun, Decl(mod.cts, 0, 0)) + +=== tests/cases/compiler/b.mts === +import a from "./mod.cjs"; +>a : Symbol(a, Decl(b.mts, 0, 6)) + +import { default as b } from "./mod.cjs"; +>default : Symbol(a, Decl(mod.cts, 0, 0)) +>b : Symbol(b, Decl(b.mts, 1, 8)) + +import c, { default as d } from "./mod.cjs"; +>c : Symbol(c, Decl(b.mts, 2, 6)) +>default : Symbol(a, Decl(mod.cts, 0, 0)) +>d : Symbol(d, Decl(b.mts, 2, 11)) + +import * as self from "./b.mjs"; +>self : Symbol(self, Decl(b.mts, 3, 6)) + +export { default } from "./mod.cjs"; +>default : Symbol(self.default, Decl(b.mts, 4, 8)) + +export { default as def } from "./mod.cjs"; +>default : Symbol(a, Decl(mod.cts, 0, 0)) +>def : Symbol(self.def, Decl(b.mts, 5, 8)) + +a === b; +>a : Symbol(a, Decl(b.mts, 0, 6)) +>b : Symbol(b, Decl(b.mts, 1, 8)) + +b === c; +>b : Symbol(b, Decl(b.mts, 1, 8)) +>c : Symbol(c, Decl(b.mts, 2, 6)) + +c === d; +>c : Symbol(c, Decl(b.mts, 2, 6)) +>d : Symbol(d, Decl(b.mts, 2, 11)) + +d === self.default; +>d : Symbol(d, Decl(b.mts, 2, 11)) +>self.default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>default : Symbol(self.default, Decl(b.mts, 4, 8)) + +self.default === self.def; +>self.default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self.def : Symbol(self.def, Decl(b.mts, 5, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>def : Symbol(self.def, Decl(b.mts, 5, 8)) + +// should all fail +a(); +>a : Symbol(a, Decl(b.mts, 0, 6)) + +b(); +>b : Symbol(b, Decl(b.mts, 1, 8)) + +c(); +>c : Symbol(c, Decl(b.mts, 2, 6)) + +d(); +>d : Symbol(d, Decl(b.mts, 2, 11)) + +self.default(); +>self.default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>default : Symbol(self.default, Decl(b.mts, 4, 8)) + +self.def(); +>self.def : Symbol(self.def, Decl(b.mts, 5, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>def : Symbol(self.def, Decl(b.mts, 5, 8)) + +// should all work +a.default(); +>a.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>a : Symbol(a, Decl(b.mts, 0, 6)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +b.default(); +>b.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>b : Symbol(b, Decl(b.mts, 1, 8)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +c.default(); +>c.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>c : Symbol(c, Decl(b.mts, 2, 6)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +d.default(); +>d.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>d : Symbol(d, Decl(b.mts, 2, 11)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +self.default.default(); +>self.default.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>self.default : Symbol(self.default, Decl(b.mts, 4, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>default : Symbol(self.default, Decl(b.mts, 4, 8)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + +self.def.default(); +>self.def.default : Symbol(a.default, Decl(mod.cts, 0, 29)) +>self.def : Symbol(self.def, Decl(b.mts, 5, 8)) +>self : Symbol(self, Decl(b.mts, 3, 6)) +>def : Symbol(self.def, Decl(b.mts, 5, 8)) +>default : Symbol(a.default, Decl(mod.cts, 0, 29)) + diff --git a/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).types b/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).types new file mode 100644 index 0000000000000..653dac121b8b0 --- /dev/null +++ b/tests/baselines/reference/moduleNodeDefaultImports(module=nodenext).types @@ -0,0 +1,131 @@ +=== tests/cases/compiler/mod.cts === +declare function fun(): void; +>fun : () => void + +export default fun; +>fun : () => void + +=== tests/cases/compiler/b.mts === +import a from "./mod.cjs"; +>a : typeof a + +import { default as b } from "./mod.cjs"; +>default : typeof a +>b : typeof a + +import c, { default as d } from "./mod.cjs"; +>c : typeof a +>default : typeof a +>d : typeof a + +import * as self from "./b.mjs"; +>self : typeof self + +export { default } from "./mod.cjs"; +>default : typeof a + +export { default as def } from "./mod.cjs"; +>default : typeof a +>def : typeof a + +a === b; +>a === b : boolean +>a : typeof a +>b : typeof a + +b === c; +>b === c : boolean +>b : typeof a +>c : typeof a + +c === d; +>c === d : boolean +>c : typeof a +>d : typeof a + +d === self.default; +>d === self.default : boolean +>d : typeof a +>self.default : typeof a +>self : typeof self +>default : typeof a + +self.default === self.def; +>self.default === self.def : boolean +>self.default : typeof a +>self : typeof self +>default : typeof a +>self.def : typeof a +>self : typeof self +>def : typeof a + +// should all fail +a(); +>a() : any +>a : typeof a + +b(); +>b() : any +>b : typeof a + +c(); +>c() : any +>c : typeof a + +d(); +>d() : any +>d : typeof a + +self.default(); +>self.default() : any +>self.default : typeof a +>self : typeof self +>default : typeof a + +self.def(); +>self.def() : any +>self.def : typeof a +>self : typeof self +>def : typeof a + +// should all work +a.default(); +>a.default() : void +>a.default : () => void +>a : typeof a +>default : () => void + +b.default(); +>b.default() : void +>b.default : () => void +>b : typeof a +>default : () => void + +c.default(); +>c.default() : void +>c.default : () => void +>c : typeof a +>default : () => void + +d.default(); +>d.default() : void +>d.default : () => void +>d : typeof a +>default : () => void + +self.default.default(); +>self.default.default() : void +>self.default.default : () => void +>self.default : typeof a +>self : typeof self +>default : typeof a +>default : () => void + +self.def.default(); +>self.def.default() : void +>self.def.default : () => void +>self.def : typeof a +>self : typeof self +>def : typeof a +>default : () => void + diff --git a/tests/baselines/reference/nonNullableAndObjectIntersections(strict=false).js b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=false).js new file mode 100644 index 0000000000000..1ac2c23d4a83a --- /dev/null +++ b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=false).js @@ -0,0 +1,21 @@ +//// [nonNullableAndObjectIntersections.ts] +// These should all resolve to never + +type T0 = NonNullable; +type T1 = NonNullable; +type T2 = null & {}; +type T3 = undefined & {}; +type T4 = null & undefined; +type T6 = null & { a: string } & {}; + +// Repro from #50519 + +type NonNullableNew = T & {}; +type NonNullableOld = T extends null | undefined ? never : T; + +type TestNew = NonNullableNew; +type TestOld = NonNullableOld; + + +//// [nonNullableAndObjectIntersections.js] +// These should all resolve to never diff --git a/tests/baselines/reference/nonNullableAndObjectIntersections(strict=false).symbols b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=false).symbols new file mode 100644 index 0000000000000..1d4558399dbbf --- /dev/null +++ b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=false).symbols @@ -0,0 +1,45 @@ +=== tests/cases/compiler/nonNullableAndObjectIntersections.ts === +// These should all resolve to never + +type T0 = NonNullable; +>T0 : Symbol(T0, Decl(nonNullableAndObjectIntersections.ts, 0, 0)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) + +type T1 = NonNullable; +>T1 : Symbol(T1, Decl(nonNullableAndObjectIntersections.ts, 2, 28)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) + +type T2 = null & {}; +>T2 : Symbol(T2, Decl(nonNullableAndObjectIntersections.ts, 3, 33)) + +type T3 = undefined & {}; +>T3 : Symbol(T3, Decl(nonNullableAndObjectIntersections.ts, 4, 20)) + +type T4 = null & undefined; +>T4 : Symbol(T4, Decl(nonNullableAndObjectIntersections.ts, 5, 25)) + +type T6 = null & { a: string } & {}; +>T6 : Symbol(T6, Decl(nonNullableAndObjectIntersections.ts, 6, 27)) +>a : Symbol(a, Decl(nonNullableAndObjectIntersections.ts, 7, 18)) + +// Repro from #50519 + +type NonNullableNew = T & {}; +>NonNullableNew : Symbol(NonNullableNew, Decl(nonNullableAndObjectIntersections.ts, 7, 36)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 11, 20)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 11, 20)) + +type NonNullableOld = T extends null | undefined ? never : T; +>NonNullableOld : Symbol(NonNullableOld, Decl(nonNullableAndObjectIntersections.ts, 11, 32)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 12, 20)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 12, 20)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 12, 20)) + +type TestNew = NonNullableNew; +>TestNew : Symbol(TestNew, Decl(nonNullableAndObjectIntersections.ts, 12, 64)) +>NonNullableNew : Symbol(NonNullableNew, Decl(nonNullableAndObjectIntersections.ts, 7, 36)) + +type TestOld = NonNullableOld; +>TestOld : Symbol(TestOld, Decl(nonNullableAndObjectIntersections.ts, 14, 36)) +>NonNullableOld : Symbol(NonNullableOld, Decl(nonNullableAndObjectIntersections.ts, 11, 32)) + diff --git a/tests/baselines/reference/nonNullableAndObjectIntersections(strict=false).types b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=false).types new file mode 100644 index 0000000000000..19b4e9c5f06e7 --- /dev/null +++ b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=false).types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/nonNullableAndObjectIntersections.ts === +// These should all resolve to never + +type T0 = NonNullable; +>T0 : never +>null : null + +type T1 = NonNullable; +>T1 : never + +type T2 = null & {}; +>T2 : never +>null : null + +type T3 = undefined & {}; +>T3 : never + +type T4 = null & undefined; +>T4 : never +>null : null + +type T6 = null & { a: string } & {}; +>T6 : never +>null : null +>a : string + +// Repro from #50519 + +type NonNullableNew = T & {}; +>NonNullableNew : NonNullableNew + +type NonNullableOld = T extends null | undefined ? never : T; +>NonNullableOld : NonNullableOld +>null : null + +type TestNew = NonNullableNew; +>TestNew : never +>null : null + +type TestOld = NonNullableOld; +>TestOld : never +>null : null + diff --git a/tests/baselines/reference/nonNullableAndObjectIntersections(strict=true).js b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=true).js new file mode 100644 index 0000000000000..51b88571c735e --- /dev/null +++ b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=true).js @@ -0,0 +1,22 @@ +//// [nonNullableAndObjectIntersections.ts] +// These should all resolve to never + +type T0 = NonNullable; +type T1 = NonNullable; +type T2 = null & {}; +type T3 = undefined & {}; +type T4 = null & undefined; +type T6 = null & { a: string } & {}; + +// Repro from #50519 + +type NonNullableNew = T & {}; +type NonNullableOld = T extends null | undefined ? never : T; + +type TestNew = NonNullableNew; +type TestOld = NonNullableOld; + + +//// [nonNullableAndObjectIntersections.js] +"use strict"; +// These should all resolve to never diff --git a/tests/baselines/reference/nonNullableAndObjectIntersections(strict=true).symbols b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=true).symbols new file mode 100644 index 0000000000000..1d4558399dbbf --- /dev/null +++ b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=true).symbols @@ -0,0 +1,45 @@ +=== tests/cases/compiler/nonNullableAndObjectIntersections.ts === +// These should all resolve to never + +type T0 = NonNullable; +>T0 : Symbol(T0, Decl(nonNullableAndObjectIntersections.ts, 0, 0)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) + +type T1 = NonNullable; +>T1 : Symbol(T1, Decl(nonNullableAndObjectIntersections.ts, 2, 28)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) + +type T2 = null & {}; +>T2 : Symbol(T2, Decl(nonNullableAndObjectIntersections.ts, 3, 33)) + +type T3 = undefined & {}; +>T3 : Symbol(T3, Decl(nonNullableAndObjectIntersections.ts, 4, 20)) + +type T4 = null & undefined; +>T4 : Symbol(T4, Decl(nonNullableAndObjectIntersections.ts, 5, 25)) + +type T6 = null & { a: string } & {}; +>T6 : Symbol(T6, Decl(nonNullableAndObjectIntersections.ts, 6, 27)) +>a : Symbol(a, Decl(nonNullableAndObjectIntersections.ts, 7, 18)) + +// Repro from #50519 + +type NonNullableNew = T & {}; +>NonNullableNew : Symbol(NonNullableNew, Decl(nonNullableAndObjectIntersections.ts, 7, 36)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 11, 20)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 11, 20)) + +type NonNullableOld = T extends null | undefined ? never : T; +>NonNullableOld : Symbol(NonNullableOld, Decl(nonNullableAndObjectIntersections.ts, 11, 32)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 12, 20)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 12, 20)) +>T : Symbol(T, Decl(nonNullableAndObjectIntersections.ts, 12, 20)) + +type TestNew = NonNullableNew; +>TestNew : Symbol(TestNew, Decl(nonNullableAndObjectIntersections.ts, 12, 64)) +>NonNullableNew : Symbol(NonNullableNew, Decl(nonNullableAndObjectIntersections.ts, 7, 36)) + +type TestOld = NonNullableOld; +>TestOld : Symbol(TestOld, Decl(nonNullableAndObjectIntersections.ts, 14, 36)) +>NonNullableOld : Symbol(NonNullableOld, Decl(nonNullableAndObjectIntersections.ts, 11, 32)) + diff --git a/tests/baselines/reference/nonNullableAndObjectIntersections(strict=true).types b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=true).types new file mode 100644 index 0000000000000..19b4e9c5f06e7 --- /dev/null +++ b/tests/baselines/reference/nonNullableAndObjectIntersections(strict=true).types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/nonNullableAndObjectIntersections.ts === +// These should all resolve to never + +type T0 = NonNullable; +>T0 : never +>null : null + +type T1 = NonNullable; +>T1 : never + +type T2 = null & {}; +>T2 : never +>null : null + +type T3 = undefined & {}; +>T3 : never + +type T4 = null & undefined; +>T4 : never +>null : null + +type T6 = null & { a: string } & {}; +>T6 : never +>null : null +>a : string + +// Repro from #50519 + +type NonNullableNew = T & {}; +>NonNullableNew : NonNullableNew + +type NonNullableOld = T extends null | undefined ? never : T; +>NonNullableOld : NonNullableOld +>null : null + +type TestNew = NonNullableNew; +>TestNew : never +>null : null + +type TestOld = NonNullableOld; +>TestOld : never +>null : null + diff --git a/tests/baselines/reference/nonNullableWithNullableGenericIndexedAccessArg.symbols b/tests/baselines/reference/nonNullableWithNullableGenericIndexedAccessArg.symbols new file mode 100644 index 0000000000000..a461d361eedcc --- /dev/null +++ b/tests/baselines/reference/nonNullableWithNullableGenericIndexedAccessArg.symbols @@ -0,0 +1,77 @@ +=== tests/cases/compiler/nonNullableWithNullableGenericIndexedAccessArg.ts === +// repro from #50539 + +interface StateSchema { +>StateSchema : Symbol(StateSchema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 0, 0)) + + states?: { +>states : Symbol(StateSchema.states, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 2, 23)) + + [key: string]: StateSchema; +>key : Symbol(key, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 4, 5)) +>StateSchema : Symbol(StateSchema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 0, 0)) + + }; +} + +declare class StateNode { +>StateNode : Symbol(StateNode, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 6, 1)) +>TStateSchema : Symbol(TStateSchema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 8, 24)) +>StateSchema : Symbol(StateSchema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 0, 0)) + + schema: TStateSchema; +>schema : Symbol(StateNode.schema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 8, 59)) +>TStateSchema : Symbol(TStateSchema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 8, 24)) +} + +type StateNodesConfig = { +>StateNodesConfig : Symbol(StateNodesConfig, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 10, 1)) +>TStateSchema : Symbol(TStateSchema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 12, 22)) +>StateSchema : Symbol(StateSchema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 0, 0)) + + [K in keyof TStateSchema["states"]]: StateNode[K]>; +>K : Symbol(K, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 13, 3)) +>TStateSchema : Symbol(TStateSchema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 12, 22)) +>StateNode : Symbol(StateNode, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 6, 1)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) +>TStateSchema : Symbol(TStateSchema, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 12, 22)) +>K : Symbol(K, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 13, 3)) + +}; + +// repro from #50539#issuecomment-1234067835 + +type Ordering = { +>Ordering : Symbol(Ordering, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 14, 2)) +>TOrderBy : Symbol(TOrderBy, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 18, 14)) + + orderBy: TOrderBy +>orderBy : Symbol(orderBy, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 18, 42)) +>TOrderBy : Symbol(TOrderBy, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 18, 14)) +} + +type Query = { +>Query : Symbol(Query, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 20, 1)) +>TOrderBy : Symbol(TOrderBy, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 22, 11)) + + order?: Ordering +>order : Symbol(order, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 22, 39)) +>Ordering : Symbol(Ordering, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 14, 2)) +>TOrderBy : Symbol(TOrderBy, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 22, 11)) +} + +type QueryHandler< +>QueryHandler : Symbol(QueryHandler, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 24, 1)) + + TQuery extends Query, +>TQuery : Symbol(TQuery, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 26, 18)) +>Query : Symbol(Query, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 20, 1)) +>TOrderBy : Symbol(TOrderBy, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 27, 35)) + + TOrderBy extends string = NonNullable["orderBy"] +>TOrderBy : Symbol(TOrderBy, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 27, 35)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) +>TQuery : Symbol(TQuery, Decl(nonNullableWithNullableGenericIndexedAccessArg.ts, 26, 18)) + +> = {} + diff --git a/tests/baselines/reference/nonNullableWithNullableGenericIndexedAccessArg.types b/tests/baselines/reference/nonNullableWithNullableGenericIndexedAccessArg.types new file mode 100644 index 0000000000000..f2bbff47ada4c --- /dev/null +++ b/tests/baselines/reference/nonNullableWithNullableGenericIndexedAccessArg.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/nonNullableWithNullableGenericIndexedAccessArg.ts === +// repro from #50539 + +interface StateSchema { + states?: { +>states : { [key: string]: StateSchema; } | undefined + + [key: string]: StateSchema; +>key : string + + }; +} + +declare class StateNode { +>StateNode : StateNode + + schema: TStateSchema; +>schema : TStateSchema +} + +type StateNodesConfig = { +>StateNodesConfig : StateNodesConfig + + [K in keyof TStateSchema["states"]]: StateNode[K]>; +}; + +// repro from #50539#issuecomment-1234067835 + +type Ordering = { +>Ordering : Ordering + + orderBy: TOrderBy +>orderBy : TOrderBy +} + +type Query = { +>Query : Query + + order?: Ordering +>order : Ordering | undefined +} + +type QueryHandler< +>QueryHandler : QueryHandler + + TQuery extends Query, + TOrderBy extends string = NonNullable["orderBy"] +> = {} + diff --git a/tests/baselines/reference/tsbuild/containerOnlyReferenced/when-solution-is-referenced-indirectly.js b/tests/baselines/reference/tsbuild/containerOnlyReferenced/when-solution-is-referenced-indirectly.js new file mode 100644 index 0000000000000..7cc61e7f319ee --- /dev/null +++ b/tests/baselines/reference/tsbuild/containerOnlyReferenced/when-solution-is-referenced-indirectly.js @@ -0,0 +1,303 @@ +Input:: +//// [/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + +//// [/src/project1/tsconfig.json] +{"compilerOptions":{"composite":true},"references":[]} + +//// [/src/project2/src/b.ts] +export const b = 10; + +//// [/src/project2/tsconfig.json] +{"compilerOptions":{"composite":true},"references":[]} + +//// [/src/project3/src/c.ts] +export const c = 10; + +//// [/src/project3/tsconfig.json] +{"compilerOptions":{"composite":true},"references":[{"path":"../project1"},{"path":"../project2"}]} + +//// [/src/project4/src/d.ts] +export const d = 10; + +//// [/src/project4/tsconfig.json] +{"compilerOptions":{"composite":true},"references":[{"path":"../project3"}]} + + + +Output:: +/lib/tsc --b /src/project4 --verbose --explainFiles +[12:00:20 AM] Projects in this build: + * src/project1/tsconfig.json + * src/project2/tsconfig.json + * src/project3/tsconfig.json + * src/project4/tsconfig.json + +[12:00:21 AM] Project 'src/project2/tsconfig.json' is out of date because output file 'src/project2/tsconfig.tsbuildinfo' does not exist + +[12:00:22 AM] Building project '/src/project2/tsconfig.json'... + +lib/lib.d.ts + Default library for target 'es3' +src/project2/src/b.ts + Matched by default include pattern '**/*' +[12:00:28 AM] Project 'src/project3/tsconfig.json' is out of date because output file 'src/project3/tsconfig.tsbuildinfo' does not exist + +[12:00:29 AM] Building project '/src/project3/tsconfig.json'... + +lib/lib.d.ts + Default library for target 'es3' +src/project3/src/c.ts + Matched by default include pattern '**/*' +[12:00:35 AM] Project 'src/project4/tsconfig.json' is out of date because output file 'src/project4/tsconfig.tsbuildinfo' does not exist + +[12:00:36 AM] Building project '/src/project4/tsconfig.json'... + +lib/lib.d.ts + Default library for target 'es3' +src/project4/src/d.ts + Matched by default include pattern '**/*' +exitCode:: ExitStatus.Success + + +//// [/src/project2/src/b.d.ts] +export declare const b = 10; + + +//// [/src/project2/src/b.js] +"use strict"; +exports.__esModule = true; +exports.b = void 0; +exports.b = 10; + + +//// [/src/project2/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../lib/lib.d.ts","./src/b.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-13368947479-export const b = 10;","signature":"-1807916688-export declare const b = 10;\r\n"}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./src/b.d.ts"},"version":"FakeTSVersion"} + +//// [/src/project2/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../lib/lib.d.ts", + "./src/b.ts" + ], + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true + }, + "./src/b.ts": { + "version": "-13368947479-export const b = 10;", + "signature": "-1807916688-export declare const b = 10;\r\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "./src/b.ts" + ], + "latestChangedDtsFile": "./src/b.d.ts" + }, + "version": "FakeTSVersion", + "size": 832 +} + +//// [/src/project3/src/c.d.ts] +export declare const c = 10; + + +//// [/src/project3/src/c.js] +"use strict"; +exports.__esModule = true; +exports.c = void 0; +exports.c = 10; + + +//// [/src/project3/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../lib/lib.d.ts","./src/c.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-12077479510-export const c = 10;","signature":"-4148571535-export declare const c = 10;\r\n"}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./src/c.d.ts"},"version":"FakeTSVersion"} + +//// [/src/project3/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../lib/lib.d.ts", + "./src/c.ts" + ], + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true + }, + "./src/c.ts": { + "version": "-12077479510-export const c = 10;", + "signature": "-4148571535-export declare const c = 10;\r\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "./src/c.ts" + ], + "latestChangedDtsFile": "./src/c.d.ts" + }, + "version": "FakeTSVersion", + "size": 832 +} + +//// [/src/project4/src/d.d.ts] +export declare const d = 10; + + +//// [/src/project4/src/d.js] +"use strict"; +exports.__esModule = true; +exports.d = void 0; +exports.d = 10; + + +//// [/src/project4/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../lib/lib.d.ts","./src/d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-10786011541-export const d = 10;","signature":"-6489226382-export declare const d = 10;\r\n"}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./src/d.d.ts"},"version":"FakeTSVersion"} + +//// [/src/project4/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../lib/lib.d.ts", + "./src/d.ts" + ], + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true + }, + "./src/d.ts": { + "version": "-10786011541-export const d = 10;", + "signature": "-6489226382-export declare const d = 10;\r\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "./src/d.ts" + ], + "latestChangedDtsFile": "./src/d.d.ts" + }, + "version": "FakeTSVersion", + "size": 832 +} + + + +Change:: modify project3 file +Input:: +//// [/src/project3/src/c.ts] +export const cc = 10; + + + +Output:: +/lib/tsc --b /src/project4 --verbose --explainFiles +[12:00:43 AM] Projects in this build: + * src/project1/tsconfig.json + * src/project2/tsconfig.json + * src/project3/tsconfig.json + * src/project4/tsconfig.json + +[12:00:44 AM] Project 'src/project2/tsconfig.json' is up to date because newest input 'src/project2/src/b.ts' is older than output 'src/project2/tsconfig.tsbuildinfo' + +[12:00:45 AM] Project 'src/project3/tsconfig.json' is out of date because output 'src/project3/tsconfig.tsbuildinfo' is older than input 'src/project3/src/c.ts' + +[12:00:46 AM] Building project '/src/project3/tsconfig.json'... + +lib/lib.d.ts + Default library for target 'es3' +src/project3/src/c.ts + Matched by default include pattern '**/*' +[12:00:52 AM] Project 'src/project4/tsconfig.json' is out of date because output 'src/project4/tsconfig.tsbuildinfo' is older than input 'src/project3' + +[12:00:53 AM] Building project '/src/project4/tsconfig.json'... + +[12:00:54 AM] Updating unchanged output timestamps of project '/src/project4/tsconfig.json'... + +lib/lib.d.ts + Default library for target 'es3' +src/project4/src/d.ts + Matched by default include pattern '**/*' +exitCode:: ExitStatus.Success + + +//// [/src/project3/src/c.d.ts] +export declare const cc = 10; + + +//// [/src/project3/src/c.js] +"use strict"; +exports.__esModule = true; +exports.cc = void 0; +exports.cc = 10; + + +//// [/src/project3/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../lib/lib.d.ts","./src/c.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-12481904019-export const cc = 10;","signature":"-2519819788-export declare const cc = 10;\r\n"}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./src/c.d.ts"},"version":"FakeTSVersion"} + +//// [/src/project3/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../lib/lib.d.ts", + "./src/c.ts" + ], + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true + }, + "./src/c.ts": { + "version": "-12481904019-export const cc = 10;", + "signature": "-2519819788-export declare const cc = 10;\r\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "./src/c.ts" + ], + "latestChangedDtsFile": "./src/c.d.ts" + }, + "version": "FakeTSVersion", + "size": 834 +} + +//// [/src/project4/tsconfig.tsbuildinfo] file changed its modified time diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js new file mode 100644 index 0000000000000..02b1358e97ad7 --- /dev/null +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js @@ -0,0 +1,148 @@ +Input:: +//// [/Users/name/projects/web/package.json] +{"name":"@this/package","type":"module","exports":{".":"./dist/index.js"}} + +//// [/Users/name/projects/web/index.ts] +import * as me from "@this/package"; +me.thing(); +export function thing(): void {} + + +//// [/Users/name/projects/web/tsconfig.json] +{"compilerOptions":{"module":"nodenext","outDir":"./dist","declarationDir":"./types","composite":true,"forceConsistentCasingInFileNames":true,"traceResolution":true}} + +//// [/a/lib/lib.esnext.full.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + + +/a/lib/tsc.js -w --explainFiles +Output:: +>> Screen clear +[12:00:23 AM] Starting compilation in watch mode... + +Found 'package.json' at '/users/name/projects/web/package.json'. +'package.json' does not have a 'typesVersions' field. +======== Resolving module '@this/package' from '/Users/name/projects/web/index.ts'. ======== +Module resolution kind is not specified, using 'NodeNext'. +File '/users/name/projects/web/package.json' exists according to earlier cached lookups. +File '/Users/name/projects/web/index.ts' exist - use it as a name resolution result. +Resolving real path for '/Users/name/projects/web/index.ts', result '/Users/name/projects/web/index.ts'. +======== Module name '@this/package' was successfully resolved to '/Users/name/projects/web/index.ts'. ======== +File '/a/lib/package.json' does not exist. +File '/a/package.json' does not exist. +File '/package.json' does not exist. +../../../../a/lib/lib.esnext.full.d.ts + Default library for target 'esnext' +index.ts + Matched by default include pattern '**/*' + Imported via "@this/package" from file 'index.ts' + File is ECMAScript module because 'package.json' has field "type" with value "module" +[12:00:36 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/Users/name/projects/web/index.ts"] +Program options: {"module":199,"outDir":"/Users/name/projects/web/dist","declarationDir":"/Users/name/projects/web/types","composite":true,"forceConsistentCasingInFileNames":true,"traceResolution":true,"watch":true,"explainFiles":true,"configFilePath":"/Users/name/projects/web/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.esnext.full.d.ts +/Users/name/projects/web/index.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.esnext.full.d.ts +/Users/name/projects/web/index.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.esnext.full.d.ts (used version) +/users/name/projects/web/index.ts (computed .d.ts during emit) + +WatchedFiles:: +/users/name/projects/web/tsconfig.json: + {"fileName":"/Users/name/projects/web/tsconfig.json","pollingInterval":250} +/users/name/projects/web/index.ts: + {"fileName":"/Users/name/projects/web/index.ts","pollingInterval":250} +/a/lib/lib.esnext.full.d.ts: + {"fileName":"/a/lib/lib.esnext.full.d.ts","pollingInterval":250} +/users/name/projects/web/package.json: + {"fileName":"/Users/name/projects/web/package.json","pollingInterval":250} +/users/name/projects/web/node_modules/@types: + {"fileName":"/Users/name/projects/web/node_modules/@types","pollingInterval":500} + +FsWatches:: + +FsWatchesRecursive:: +/users/name/projects/web: + {"directoryName":"/users/name/projects/web"} + +exitCode:: ExitStatus.undefined + +//// [/Users/name/projects/web/dist/index.js] +import * as me from "@this/package"; +me.thing(); +export function thing() { } + + +//// [/Users/name/projects/web/types/index.d.ts] +export declare function thing(): void; + + +//// [/Users/name/projects/web/dist/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../../a/lib/lib.esnext.full.d.ts","../index.ts"],"fileInfos":[{"version":"-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }","affectsGlobalScope":true,"impliedFormat":1},{"version":"14361483761-import * as me from \"@this/package\";\nme.thing();\nexport function thing(): void {}\n","signature":"-2724770439-export declare function thing(): void;\n","impliedFormat":99}],"options":{"composite":true,"declarationDir":"../types","module":199,"outDir":"./"},"fileIdsList":[[2]],"referencedMap":[[2,1]],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"../types/index.d.ts"},"version":"FakeTSVersion"} + +//// [/Users/name/projects/web/dist/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../../a/lib/lib.esnext.full.d.ts", + "../index.ts" + ], + "fileNamesList": [ + [ + "../index.ts" + ] + ], + "fileInfos": { + "../../../../../a/lib/lib.esnext.full.d.ts": { + "version": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "signature": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "affectsGlobalScope": true, + "impliedFormat": "commonjs" + }, + "../index.ts": { + "version": "14361483761-import * as me from \"@this/package\";\nme.thing();\nexport function thing(): void {}\n", + "signature": "-2724770439-export declare function thing(): void;\n", + "impliedFormat": "esnext" + } + }, + "options": { + "composite": true, + "declarationDir": "../types", + "module": 199, + "outDir": "./" + }, + "referencedMap": { + "../index.ts": [ + "../index.ts" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../../a/lib/lib.esnext.full.d.ts", + "../index.ts" + ], + "latestChangedDtsFile": "../types/index.d.ts" + }, + "version": "FakeTSVersion", + "size": 974 +} + diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js new file mode 100644 index 0000000000000..efcf899a34ffa --- /dev/null +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js @@ -0,0 +1,141 @@ +Input:: +//// [/Users/name/projects/web/src/bin.ts] +import { foo } from "yargs"; + +//// [/Users/name/projects/web/node_modules/@types/yargs/index.d.ts] +export function foo(): void; + +//// [/Users/name/projects/web/node_modules/@types/yargs/index.d.mts] +export function foo(): void; + +//// [/Users/name/projects/web/node_modules/@types/yargs/package.json] +{"name":"yargs","version":"17.0.12","exports":{".":{"types":{"import":"./index.d.mts","default":"./index.d.ts"}}}} + +//// [/Users/name/projects/web/tsconfig.json] +{"compilerOptions":{"moduleResolution":"nodenext","forceConsistentCasingInFileNames":true,"traceResolution":true}} + +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + + +/a/lib/tsc.js --w --explainFiles +Output:: +>> Screen clear +[12:00:35 AM] Starting compilation in watch mode... + +File '/users/name/projects/web/src/package.json' does not exist. +File '/users/name/projects/web/package.json' does not exist. +File '/users/name/projects/package.json' does not exist. +File '/users/name/package.json' does not exist. +File '/users/package.json' does not exist. +File '/package.json' does not exist. +======== Resolving module 'yargs' from '/Users/name/projects/web/src/bin.ts'. ======== +Explicitly specified module resolution kind: 'NodeNext'. +File '/users/name/projects/web/src/package.json' does not exist according to earlier cached lookups. +File '/users/name/projects/web/package.json' does not exist according to earlier cached lookups. +File '/users/name/projects/package.json' does not exist according to earlier cached lookups. +File '/users/name/package.json' does not exist according to earlier cached lookups. +File '/users/package.json' does not exist according to earlier cached lookups. +File '/package.json' does not exist according to earlier cached lookups. +Loading module 'yargs' from 'node_modules' folder, target file type 'TypeScript'. +Directory '/Users/name/projects/web/src/node_modules' does not exist, skipping all lookups in it. +File '/Users/name/projects/web/node_modules/yargs.ts' does not exist. +File '/Users/name/projects/web/node_modules/yargs.tsx' does not exist. +File '/Users/name/projects/web/node_modules/yargs.d.ts' does not exist. +Found 'package.json' at '/Users/name/projects/web/node_modules/@types/yargs/package.json'. +'package.json' does not have a 'typesVersions' field. +File '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' exist - use it as a name resolution result. +Resolving real path for '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts', result '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts'. +======== Module name 'yargs' was successfully resolved to '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' with Package ID 'yargs/index.d.ts@17.0.12'. ======== +File '/users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. +======== Resolving type reference directive 'yargs', containing file '/Users/name/projects/web/__inferred type names__.ts', root directory '/Users/name/projects/web/node_modules/@types'. ======== +Resolving with primary search path '/Users/name/projects/web/node_modules/@types'. +File '/Users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. +'package.json' does not have a 'typings' field. +'package.json' does not have a 'types' field. +File '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' exist - use it as a name resolution result. +Resolving real path for '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts', result '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts'. +======== Type reference directive 'yargs' was successfully resolved to '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' with Package ID 'yargs/index.d.ts@17.0.12', primary: true. ======== +File '/a/lib/package.json' does not exist. +File '/a/package.json' does not exist. +File '/package.json' does not exist according to earlier cached lookups. +../../../../a/lib/lib.d.ts + Default library for target 'es3' +node_modules/@types/yargs/index.d.ts + Imported via "yargs" from file 'src/bin.ts' with packageId 'yargs/index.d.ts@17.0.12' + Entry point for implicit type library 'yargs' with packageId 'yargs/index.d.ts@17.0.12' + File is CommonJS module because 'node_modules/@types/yargs/package.json' does not have field "type" +src/bin.ts + Matched by default include pattern '**/*' + File is CommonJS module because 'package.json' was not found +[12:00:38 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/Users/name/projects/web/src/bin.ts"] +Program options: {"moduleResolution":99,"forceConsistentCasingInFileNames":true,"traceResolution":true,"watch":true,"explainFiles":true,"configFilePath":"/Users/name/projects/web/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/Users/name/projects/web/node_modules/@types/yargs/index.d.ts +/Users/name/projects/web/src/bin.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.d.ts +/Users/name/projects/web/node_modules/@types/yargs/index.d.ts +/Users/name/projects/web/src/bin.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.d.ts (used version) +/users/name/projects/web/node_modules/@types/yargs/index.d.ts (used version) +/users/name/projects/web/src/bin.ts (used version) + +WatchedFiles:: +/users/name/projects/web/tsconfig.json: + {"fileName":"/Users/name/projects/web/tsconfig.json","pollingInterval":250} +/users/name/projects/web/src/bin.ts: + {"fileName":"/Users/name/projects/web/src/bin.ts","pollingInterval":250} +/users/name/projects/web/node_modules/@types/yargs/index.d.ts: + {"fileName":"/Users/name/projects/web/node_modules/@types/yargs/index.d.ts","pollingInterval":250} +/a/lib/lib.d.ts: + {"fileName":"/a/lib/lib.d.ts","pollingInterval":250} +/users/name/projects/web/node_modules/@types/yargs/package.json: + {"fileName":"/Users/name/projects/web/node_modules/@types/yargs/package.json","pollingInterval":250} +/users/name/projects/web/src/package.json: + {"fileName":"/Users/name/projects/web/src/package.json","pollingInterval":250} +/users/name/projects/web/package.json: + {"fileName":"/Users/name/projects/web/package.json","pollingInterval":250} +/users/name/projects/package.json: + {"fileName":"/Users/name/projects/package.json","pollingInterval":250} + +FsWatches:: +/users/name/projects/web: + {"directoryName":"/Users/name/projects/web"} + +FsWatchesRecursive:: +/users/name/projects/web/src: + {"directoryName":"/users/name/projects/web/src"} +/users/name/projects/web/node_modules: + {"directoryName":"/Users/name/projects/web/node_modules"} +/users/name/projects/web/node_modules/@types: + {"directoryName":"/Users/name/projects/web/node_modules/@types"} +/users/name/projects/web: + {"directoryName":"/users/name/projects/web"} + +exitCode:: ExitStatus.undefined + +//// [/Users/name/projects/web/src/bin.js] +"use strict"; +exports.__esModule = true; + + diff --git a/tests/baselines/reference/tscWatch/watchApi/verify-that-module-resolution-with-json-extension-works-when-returned-without-extension.js b/tests/baselines/reference/tscWatch/watchApi/verify-that-module-resolution-with-json-extension-works-when-returned-without-extension.js index 8cf3621e0c5f0..0e85dbe7067f7 100644 --- a/tests/baselines/reference/tscWatch/watchApi/verify-that-module-resolution-with-json-extension-works-when-returned-without-extension.js +++ b/tests/baselines/reference/tscWatch/watchApi/verify-that-module-resolution-with-json-extension-works-when-returned-without-extension.js @@ -35,7 +35,7 @@ Output:: settings.json:1:1 1 {"content":"Print this"}   ~ - This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. + This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. [12:00:26 AM] Found 1 error. Watching for file changes. diff --git a/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=false).js b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=false).js new file mode 100644 index 0000000000000..c30c4d6723deb --- /dev/null +++ b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=false).js @@ -0,0 +1,23 @@ +//// [undefinedAsDiscriminantWithUnknown.ts] +type S = +| { type: 'string', value: string } +| { type: 'number', value: number } +| { type: 'unknown', value: unknown } +| { value: undefined }; + +declare var s: S + +if (s.value !== undefined) { + s; +} +else { + s; +} + +//// [undefinedAsDiscriminantWithUnknown.js] +if (s.value !== undefined) { + s; +} +else { + s; +} diff --git a/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=false).symbols b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=false).symbols new file mode 100644 index 0000000000000..13da7db0555c1 --- /dev/null +++ b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=false).symbols @@ -0,0 +1,36 @@ +=== tests/cases/compiler/undefinedAsDiscriminantWithUnknown.ts === +type S = +>S : Symbol(S, Decl(undefinedAsDiscriminantWithUnknown.ts, 0, 0)) + +| { type: 'string', value: string } +>type : Symbol(type, Decl(undefinedAsDiscriminantWithUnknown.ts, 1, 3)) +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 1, 19)) + +| { type: 'number', value: number } +>type : Symbol(type, Decl(undefinedAsDiscriminantWithUnknown.ts, 2, 3)) +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 2, 19)) + +| { type: 'unknown', value: unknown } +>type : Symbol(type, Decl(undefinedAsDiscriminantWithUnknown.ts, 3, 3)) +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 3, 20)) + +| { value: undefined }; +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 4, 3)) + +declare var s: S +>s : Symbol(s, Decl(undefinedAsDiscriminantWithUnknown.ts, 6, 11)) +>S : Symbol(S, Decl(undefinedAsDiscriminantWithUnknown.ts, 0, 0)) + +if (s.value !== undefined) { +>s.value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 1, 19), Decl(undefinedAsDiscriminantWithUnknown.ts, 2, 19), Decl(undefinedAsDiscriminantWithUnknown.ts, 3, 20), Decl(undefinedAsDiscriminantWithUnknown.ts, 4, 3)) +>s : Symbol(s, Decl(undefinedAsDiscriminantWithUnknown.ts, 6, 11)) +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 1, 19), Decl(undefinedAsDiscriminantWithUnknown.ts, 2, 19), Decl(undefinedAsDiscriminantWithUnknown.ts, 3, 20), Decl(undefinedAsDiscriminantWithUnknown.ts, 4, 3)) +>undefined : Symbol(undefined) + + s; +>s : Symbol(s, Decl(undefinedAsDiscriminantWithUnknown.ts, 6, 11)) +} +else { + s; +>s : Symbol(s, Decl(undefinedAsDiscriminantWithUnknown.ts, 6, 11)) +} diff --git a/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=false).types b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=false).types new file mode 100644 index 0000000000000..af09de9d3d839 --- /dev/null +++ b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=false).types @@ -0,0 +1,36 @@ +=== tests/cases/compiler/undefinedAsDiscriminantWithUnknown.ts === +type S = +>S : { type: 'string'; value: string; } | { type: 'number'; value: number; } | { type: 'unknown'; value: unknown; } | { value: undefined; } + +| { type: 'string', value: string } +>type : "string" +>value : string + +| { type: 'number', value: number } +>type : "number" +>value : number + +| { type: 'unknown', value: unknown } +>type : "unknown" +>value : unknown + +| { value: undefined }; +>value : undefined + +declare var s: S +>s : S + +if (s.value !== undefined) { +>s.value !== undefined : boolean +>s.value : unknown +>s : S +>value : unknown +>undefined : undefined + + s; +>s : S +} +else { + s; +>s : S +} diff --git a/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=true).js b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=true).js new file mode 100644 index 0000000000000..c30c4d6723deb --- /dev/null +++ b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=true).js @@ -0,0 +1,23 @@ +//// [undefinedAsDiscriminantWithUnknown.ts] +type S = +| { type: 'string', value: string } +| { type: 'number', value: number } +| { type: 'unknown', value: unknown } +| { value: undefined }; + +declare var s: S + +if (s.value !== undefined) { + s; +} +else { + s; +} + +//// [undefinedAsDiscriminantWithUnknown.js] +if (s.value !== undefined) { + s; +} +else { + s; +} diff --git a/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=true).symbols b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=true).symbols new file mode 100644 index 0000000000000..13da7db0555c1 --- /dev/null +++ b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=true).symbols @@ -0,0 +1,36 @@ +=== tests/cases/compiler/undefinedAsDiscriminantWithUnknown.ts === +type S = +>S : Symbol(S, Decl(undefinedAsDiscriminantWithUnknown.ts, 0, 0)) + +| { type: 'string', value: string } +>type : Symbol(type, Decl(undefinedAsDiscriminantWithUnknown.ts, 1, 3)) +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 1, 19)) + +| { type: 'number', value: number } +>type : Symbol(type, Decl(undefinedAsDiscriminantWithUnknown.ts, 2, 3)) +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 2, 19)) + +| { type: 'unknown', value: unknown } +>type : Symbol(type, Decl(undefinedAsDiscriminantWithUnknown.ts, 3, 3)) +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 3, 20)) + +| { value: undefined }; +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 4, 3)) + +declare var s: S +>s : Symbol(s, Decl(undefinedAsDiscriminantWithUnknown.ts, 6, 11)) +>S : Symbol(S, Decl(undefinedAsDiscriminantWithUnknown.ts, 0, 0)) + +if (s.value !== undefined) { +>s.value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 1, 19), Decl(undefinedAsDiscriminantWithUnknown.ts, 2, 19), Decl(undefinedAsDiscriminantWithUnknown.ts, 3, 20), Decl(undefinedAsDiscriminantWithUnknown.ts, 4, 3)) +>s : Symbol(s, Decl(undefinedAsDiscriminantWithUnknown.ts, 6, 11)) +>value : Symbol(value, Decl(undefinedAsDiscriminantWithUnknown.ts, 1, 19), Decl(undefinedAsDiscriminantWithUnknown.ts, 2, 19), Decl(undefinedAsDiscriminantWithUnknown.ts, 3, 20), Decl(undefinedAsDiscriminantWithUnknown.ts, 4, 3)) +>undefined : Symbol(undefined) + + s; +>s : Symbol(s, Decl(undefinedAsDiscriminantWithUnknown.ts, 6, 11)) +} +else { + s; +>s : Symbol(s, Decl(undefinedAsDiscriminantWithUnknown.ts, 6, 11)) +} diff --git a/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=true).types b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=true).types new file mode 100644 index 0000000000000..69d640efe7337 --- /dev/null +++ b/tests/baselines/reference/undefinedAsDiscriminantWithUnknown(strictnullchecks=true).types @@ -0,0 +1,36 @@ +=== tests/cases/compiler/undefinedAsDiscriminantWithUnknown.ts === +type S = +>S : { type: 'string'; value: string; } | { type: 'number'; value: number; } | { type: 'unknown'; value: unknown; } | { value: undefined; } + +| { type: 'string', value: string } +>type : "string" +>value : string + +| { type: 'number', value: number } +>type : "number" +>value : number + +| { type: 'unknown', value: unknown } +>type : "unknown" +>value : unknown + +| { value: undefined }; +>value : undefined + +declare var s: S +>s : S + +if (s.value !== undefined) { +>s.value !== undefined : boolean +>s.value : unknown +>s : S +>value : unknown +>undefined : undefined + + s; +>s : { type: "string"; value: string; } | { type: "number"; value: number; } | { type: "unknown"; value: unknown; } +} +else { + s; +>s : { type: "unknown"; value: unknown; } | { value: undefined; } +} diff --git a/tests/cases/compiler/emptyAnonymousObjectNarrowing.ts b/tests/cases/compiler/emptyAnonymousObjectNarrowing.ts new file mode 100644 index 0000000000000..f37c3ee8c47fa --- /dev/null +++ b/tests/cases/compiler/emptyAnonymousObjectNarrowing.ts @@ -0,0 +1,75 @@ +// @strictNullChecks: true,false + +declare let nonNull: {}; +if (nonNull === "foo") { + nonNull; +} +else { + nonNull; +} + +declare let obj: { a: string }; +if (nonNull === obj) { + nonNull; +} +else { + nonNull; +} + +function f1(x: T) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} + +function f2(x: T) { + if (nonNull === x) { + nonNull; + } + else { + nonNull; + } +} + +declare let union: "xyz" | { a: string } | undefined; +if (nonNull === union) { + nonNull; +} +else { + nonNull; +} + +if (nonNull === undefined) { + nonNull; +} +else { + nonNull; +} + +if (nonNull === null) { + nonNull; +} +else { + nonNull; +} + +if (nonNull == undefined) { + nonNull; +} +else { + nonNull; +} + +// Repro from #50567 +const foo = (value: unknown): string => { + if (!value) { + return 'foo'; + } + if (value === 'xyz') { + return value; // Type '{}' is not assignable to type 'string'. + } + return ''; +}; diff --git a/tests/cases/compiler/esModuleInteropDefaultImports.ts b/tests/cases/compiler/esModuleInteropDefaultImports.ts new file mode 100644 index 0000000000000..0ddd2df567756 --- /dev/null +++ b/tests/cases/compiler/esModuleInteropDefaultImports.ts @@ -0,0 +1,36 @@ +// @esModuleInterop: true +// @filename: mod.ts +declare function fun(): void; +export default fun; +// @filename: a.ts +import mod = require("./mod"); +export = mod; +// @filename: b.ts +import a from "./a"; +import { default as b } from "./a"; +import c, { default as d } from "./a"; +import * as self from "./b"; +export { default } from "./a"; +export { default as def } from "./a"; + +a === b; +b === c; +c === d; +d === self.default; +self.default === self.def; + +// should all fail +a(); +b(); +c(); +d(); +self.default(); +self.def(); + +// should all work +a.default(); +b.default(); +c.default(); +d.default(); +self.default.default(); +self.def.default(); \ No newline at end of file diff --git a/tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts b/tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts new file mode 100644 index 0000000000000..c0e25cd85454e --- /dev/null +++ b/tests/cases/compiler/excessPropertyCheckingIntersectionWithConditional.ts @@ -0,0 +1,4 @@ +type Foo = K extends unknown ? { a: number } : unknown +const createDefaultExample = (x: K): Foo & { x: K; } => { + return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2 +} \ No newline at end of file diff --git a/tests/cases/compiler/inKeywordAndUnknown.ts b/tests/cases/compiler/inKeywordAndUnknown.ts new file mode 100644 index 0000000000000..745dfbc1f9af5 --- /dev/null +++ b/tests/cases/compiler/inKeywordAndUnknown.ts @@ -0,0 +1,18 @@ +// @strict: true + +// Repro from #50531 + +function f(x: {}, y: unknown) { + if (!("a" in x)) { + return; + } + x; // {} + if (!y) { + return; + } + y; // {} + if (!("a" in y)) { + return; + } + y; // {} +} diff --git a/tests/cases/compiler/jsxIntrinsicElementsCompatability.tsx b/tests/cases/compiler/jsxIntrinsicElementsCompatability.tsx new file mode 100644 index 0000000000000..faaec4fe77808 --- /dev/null +++ b/tests/cases/compiler/jsxIntrinsicElementsCompatability.tsx @@ -0,0 +1,12 @@ +// @strict: true +// @jsx: react +/// +import * as React from "react"; +function SomeComponent(props: { element?: T } & JSX.IntrinsicElements[T]): JSX.Element { + // Just so the return value is RectElement, the rendered element doesnt matter + return
+} + +function Test(el: T) { + return +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleNodeDefaultImports.ts b/tests/cases/compiler/moduleNodeDefaultImports.ts new file mode 100644 index 0000000000000..906de682bd610 --- /dev/null +++ b/tests/cases/compiler/moduleNodeDefaultImports.ts @@ -0,0 +1,33 @@ +// @module: node16,nodenext +// @filename: mod.cts +declare function fun(): void; +export default fun; +// @filename: b.mts +import a from "./mod.cjs"; +import { default as b } from "./mod.cjs"; +import c, { default as d } from "./mod.cjs"; +import * as self from "./b.mjs"; +export { default } from "./mod.cjs"; +export { default as def } from "./mod.cjs"; + +a === b; +b === c; +c === d; +d === self.default; +self.default === self.def; + +// should all fail +a(); +b(); +c(); +d(); +self.default(); +self.def(); + +// should all work +a.default(); +b.default(); +c.default(); +d.default(); +self.default.default(); +self.def.default(); \ No newline at end of file diff --git a/tests/cases/compiler/nonNullableAndObjectIntersections.ts b/tests/cases/compiler/nonNullableAndObjectIntersections.ts new file mode 100644 index 0000000000000..a9e8319aef266 --- /dev/null +++ b/tests/cases/compiler/nonNullableAndObjectIntersections.ts @@ -0,0 +1,18 @@ +// @strict: true, false + +// These should all resolve to never + +type T0 = NonNullable; +type T1 = NonNullable; +type T2 = null & {}; +type T3 = undefined & {}; +type T4 = null & undefined; +type T6 = null & { a: string } & {}; + +// Repro from #50519 + +type NonNullableNew = T & {}; +type NonNullableOld = T extends null | undefined ? never : T; + +type TestNew = NonNullableNew; +type TestOld = NonNullableOld; diff --git a/tests/cases/compiler/nonNullableWithNullableGenericIndexedAccessArg.ts b/tests/cases/compiler/nonNullableWithNullableGenericIndexedAccessArg.ts new file mode 100644 index 0000000000000..8b8d4dc0e24ca --- /dev/null +++ b/tests/cases/compiler/nonNullableWithNullableGenericIndexedAccessArg.ts @@ -0,0 +1,33 @@ +// @noEmit: true +// @strict: true + +// repro from #50539 + +interface StateSchema { + states?: { + [key: string]: StateSchema; + }; +} + +declare class StateNode { + schema: TStateSchema; +} + +type StateNodesConfig = { + [K in keyof TStateSchema["states"]]: StateNode[K]>; +}; + +// repro from #50539#issuecomment-1234067835 + +type Ordering = { + orderBy: TOrderBy +} + +type Query = { + order?: Ordering +} + +type QueryHandler< + TQuery extends Query, + TOrderBy extends string = NonNullable["orderBy"] +> = {} diff --git a/tests/cases/compiler/undefinedAsDiscriminantWithUnknown.ts b/tests/cases/compiler/undefinedAsDiscriminantWithUnknown.ts new file mode 100644 index 0000000000000..6a6cf1007b0bb --- /dev/null +++ b/tests/cases/compiler/undefinedAsDiscriminantWithUnknown.ts @@ -0,0 +1,16 @@ +// @strictNullChecks: true,false + +type S = +| { type: 'string', value: string } +| { type: 'number', value: number } +| { type: 'unknown', value: unknown } +| { value: undefined }; + +declare var s: S + +if (s.value !== undefined) { + s; +} +else { + s; +} \ No newline at end of file diff --git a/tests/cases/conformance/controlFlow/controlFlowGenericTypes.ts b/tests/cases/conformance/controlFlow/controlFlowGenericTypes.ts index 3e67f3247da3d..50c2c4fdf147e 100644 --- a/tests/cases/conformance/controlFlow/controlFlowGenericTypes.ts +++ b/tests/cases/conformance/controlFlow/controlFlowGenericTypes.ts @@ -211,3 +211,11 @@ function update(control : T | undefined, k control[key] = value; } } + +// Repro from #50465 + +type Column = (keyof T extends never ? { id?: number | string } : { id: T }) & { title?: string; } + +function getColumnProperty(column: Column, key: keyof Column) { + return column[key]; +}