diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 301c28e062c76..9620a01c5ee95 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3488,7 +3488,11 @@ namespace ts { } if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Node12 || getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeNext) { const isSyncImport = (currentSourceFile.impliedNodeFormat === ModuleKind.CommonJS && !findAncestor(location, isImportCall)) || !!findAncestor(location, isImportEqualsDeclaration); - if (isSyncImport && sourceFile.impliedNodeFormat === ModuleKind.ESNext) { + const overrideClauseHost = findAncestor(location, l => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l)) as ImportTypeNode | ImportDeclaration | ExportDeclaration | undefined; + const overrideClause = overrideClauseHost && isImportTypeNode(overrideClauseHost) ? overrideClauseHost.assertions?.assertClause : overrideClauseHost?.assertClause; + // An override clause will take effect for type-only imports and import types, and allows importing the types across formats, regardless of + // normal mode restrictions + if (isSyncImport && sourceFile.impliedNodeFormat === ModuleKind.ESNext && !getResolutionModeOverrideForClause(overrideClause)) { error(errorNode, Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead, moduleReference); } if (mode === ModuleKind.ESNext && compilerOptions.resolveJsonModule && resolvedModule.extension === Extension.Json) { @@ -5969,7 +5973,7 @@ namespace ts { return top; } - function getSpecifierForModuleSymbol(symbol: Symbol, context: NodeBuilderContext) { + function getSpecifierForModuleSymbol(symbol: Symbol, context: NodeBuilderContext, overrideImportMode?: SourceFile["impliedNodeFormat"]) { let file = getDeclarationOfKind(symbol, SyntaxKind.SourceFile); if (!file) { const equivalentFileSymbol = firstDefined(symbol.declarations, d => getFileSymbolIfFileSymbolExportEqualsContainer(d, symbol)); @@ -6002,8 +6006,10 @@ namespace ts { return getSourceFileOfNode(getNonAugmentationDeclaration(symbol)!).fileName; // A resolver may not be provided for baselines and errors - in those cases we use the fileName in full } const contextFile = getSourceFileOfNode(getOriginalNode(context.enclosingDeclaration)); + const resolutionMode = overrideImportMode || contextFile?.impliedNodeFormat; + const cacheKey = getSpecifierCacheKey(contextFile.path, resolutionMode); const links = getSymbolLinks(symbol); - let specifier = links.specifierCache && links.specifierCache.get(contextFile.path); + let specifier = links.specifierCache && links.specifierCache.get(cacheKey); if (!specifier) { const isBundle = !!outFile(compilerOptions); // For declaration bundles, we need to generate absolute paths relative to the common source dir for imports, @@ -6018,12 +6024,25 @@ namespace ts { specifierCompilerOptions, contextFile, moduleResolverHost, - { importModuleSpecifierPreference: isBundle ? "non-relative" : "project-relative", importModuleSpecifierEnding: isBundle ? "minimal" : undefined }, + { + importModuleSpecifierPreference: isBundle ? "non-relative" : "project-relative", + importModuleSpecifierEnding: isBundle ? "minimal" + : resolutionMode === ModuleKind.ESNext ? "js" + : undefined, + overrideImportMode: + overrideImportMode === ModuleKind.CommonJS ? "require" + : overrideImportMode === ModuleKind.ESNext ? "import" + : undefined + }, )); links.specifierCache ??= new Map(); - links.specifierCache.set(contextFile.path, specifier); + links.specifierCache.set(cacheKey, specifier); } return specifier; + + function getSpecifierCacheKey(path: string, mode: SourceFile["impliedNodeFormat"] | undefined) { + return mode === undefined ? path : `${mode}|${path}`; + } } function symbolToEntityNameNode(symbol: Symbol): EntityName { @@ -6039,13 +6058,53 @@ namespace ts { // module is root, must use `ImportTypeNode` const nonRootParts = chain.length > 1 ? createAccessFromSymbolChain(chain, chain.length - 1, 1) : undefined; const typeParameterNodes = overrideTypeArguments || lookupTypeParameterNodes(chain, 0, context); - const specifier = getSpecifierForModuleSymbol(chain[0], context); + const contextFile = getSourceFileOfNode(getOriginalNode(context.enclosingDeclaration)); + const targetFile = getSourceFileOfModule(chain[0]); + let specifier: string | undefined; + let assertion: ImportTypeAssertionContainer | undefined; + if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Node12 || getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeNext) { + // An `import` type directed at an esm format file is only going to resolve in esm mode - set the esm mode assertion + if (targetFile?.impliedNodeFormat === ModuleKind.ESNext && targetFile.impliedNodeFormat !== contextFile?.impliedNodeFormat) { + specifier = getSpecifierForModuleSymbol(chain[0], context, ModuleKind.ESNext); + assertion = factory.createImportTypeAssertionContainer(factory.createAssertClause(factory.createNodeArray([ + factory.createAssertEntry( + factory.createStringLiteral("resolution-mode"), + factory.createStringLiteral("import") + ) + ]))); + } + } + if (!specifier) { + specifier = getSpecifierForModuleSymbol(chain[0], context); + } if (!(context.flags & NodeBuilderFlags.AllowNodeModulesRelativePaths) && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Classic && specifier.indexOf("/node_modules/") >= 0) { - // If ultimately we can only name the symbol with a reference that dives into a `node_modules` folder, we should error - // since declaration files with these kinds of references are liable to fail when published :( - context.encounteredError = true; - if (context.tracker.reportLikelyUnsafeImportRequiredError) { - context.tracker.reportLikelyUnsafeImportRequiredError(specifier); + const oldSpecifier = specifier; + if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Node12 || getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeNext) { + // We might be able to write a portable import type using a mode override; try specifier generation again, but with a different mode set + const swappedMode = contextFile?.impliedNodeFormat === ModuleKind.ESNext ? ModuleKind.CommonJS : ModuleKind.ESNext; + specifier = getSpecifierForModuleSymbol(chain[0], context, swappedMode); + + if (specifier.indexOf("/node_modules/") >= 0) { + // Still unreachable :( + specifier = oldSpecifier; + } + else { + assertion = factory.createImportTypeAssertionContainer(factory.createAssertClause(factory.createNodeArray([ + factory.createAssertEntry( + factory.createStringLiteral("resolution-mode"), + factory.createStringLiteral(swappedMode === ModuleKind.ESNext ? "import" : "require") + ) + ]))); + } + } + + if (!assertion) { + // If ultimately we can only name the symbol with a reference that dives into a `node_modules` folder, we should error + // since declaration files with these kinds of references are liable to fail when published :( + context.encounteredError = true; + if (context.tracker.reportLikelyUnsafeImportRequiredError) { + context.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier); + } } } const lit = factory.createLiteralTypeNode(factory.createStringLiteral(specifier)); @@ -6056,12 +6115,12 @@ namespace ts { const lastId = isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right; lastId.typeArguments = undefined; } - return factory.createImportTypeNode(lit, nonRootParts as EntityName, typeParameterNodes as readonly TypeNode[], isTypeOf); + return factory.createImportTypeNode(lit, assertion, nonRootParts as EntityName, typeParameterNodes as readonly TypeNode[], isTypeOf); } else { const splitNode = getTopmostIndexedAccessType(nonRootParts); const qualifier = (splitNode.objectType as TypeReferenceNode).typeName; - return factory.createIndexedAccessTypeNode(factory.createImportTypeNode(lit, qualifier, typeParameterNodes as readonly TypeNode[], isTypeOf), splitNode.indexType); + return factory.createIndexedAccessTypeNode(factory.createImportTypeNode(lit, assertion, qualifier, typeParameterNodes as readonly TypeNode[], isTypeOf), splitNode.indexType); } } @@ -35124,6 +35183,16 @@ namespace ts { function checkImportType(node: ImportTypeNode) { checkSourceElement(node.argument); + + if (node.assertions) { + const override = getResolutionModeOverrideForClause(node.assertions.assertClause, grammarErrorOnNode); + if (override) { + if (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node12 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) { + grammarErrorOnNode(node.assertions.assertClause, Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext); + } + } + } + getTypeFromTypeNode(node); } @@ -39952,6 +40021,15 @@ namespace ts { function checkAssertClause(declaration: ImportDeclaration | ExportDeclaration) { if (declaration.assertClause) { + const validForTypeAssertions = isExclusivelyTypeOnlyImportOrExport(declaration); + const override = getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined); + if (validForTypeAssertions && override) { + if (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node12 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) { + return grammarErrorOnNode(declaration.assertClause, Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext); + } + return; // Other grammar checks do not apply to type-only imports with resolution mode assertions + } + const mode = (moduleKind === ModuleKind.NodeNext) && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier); if (mode !== ModuleKind.ESNext && moduleKind !== ModuleKind.ESNext) { return grammarErrorOnNode(declaration.assertClause, @@ -39963,6 +40041,10 @@ namespace ts { if (isImportDeclaration(declaration) ? declaration.importClause?.isTypeOnly : declaration.isTypeOnly) { return grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports); } + + if (override) { + return grammarErrorOnNode(declaration.assertClause, Diagnostics.resolution_mode_can_only_be_set_for_type_only_imports); + } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a88ccc2f9e08f..97315730f5bb6 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1408,6 +1408,18 @@ "category": "Error", "code": 1453 }, + "`resolution-mode` can only be set for type-only imports.": { + "category": "Error", + "code": 1454 + }, + "`resolution-mode` is the only valid key for type import assertions.": { + "category": "Error", + "code": 1455 + }, + "Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`.": { + "category": "Error", + "code": 1456 + }, "The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 22f2cd845ec80..6992c0d5d0780 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2386,6 +2386,19 @@ namespace ts { writeKeyword("import"); writePunctuation("("); emit(node.argument); + if (node.assertions) { + writePunctuation(","); + writeSpace(); + writePunctuation("{"); + writeSpace(); + writeKeyword("assert"); + writePunctuation(":"); + writeSpace(); + const elements = node.assertions.assertClause.elements; + emitList(node.assertions.assertClause, elements, ListFormat.ImportClauseEntries); + writeSpace(); + writePunctuation("}"); + } writePunctuation(")"); if (node.qualifier) { writePunctuation("."); diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index afba634ecb809..2363313bed156 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -293,6 +293,8 @@ namespace ts { updateAssertClause, createAssertEntry, updateAssertEntry, + createImportTypeAssertionContainer, + updateImportTypeAssertionContainer, createNamespaceImport, updateNamespaceImport, createNamespaceExport, @@ -2036,9 +2038,24 @@ namespace ts { } // @api - function createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf = false) { + function createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; + function createImportTypeNode(argument: TypeNode, assertions?: ImportTypeAssertionContainer, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; + function createImportTypeNode( + argument: TypeNode, + qualifierOrAssertions?: EntityName | ImportTypeAssertionContainer, + typeArgumentsOrQualifier?: readonly TypeNode[] | EntityName, + isTypeOfOrTypeArguments?: boolean | readonly TypeNode[], + isTypeOf?: boolean + ) { + const assertion = qualifierOrAssertions && qualifierOrAssertions.kind === SyntaxKind.ImportTypeAssertionContainer ? qualifierOrAssertions : undefined; + const qualifier = qualifierOrAssertions && isEntityName(qualifierOrAssertions) ? qualifierOrAssertions + : typeArgumentsOrQualifier && !isArray(typeArgumentsOrQualifier) ? typeArgumentsOrQualifier : undefined; + const typeArguments = isArray(typeArgumentsOrQualifier) ? typeArgumentsOrQualifier : isArray(isTypeOfOrTypeArguments) ? isTypeOfOrTypeArguments : undefined; + isTypeOf = typeof isTypeOfOrTypeArguments === "boolean" ? isTypeOfOrTypeArguments : typeof isTypeOf === "boolean" ? isTypeOf : false; + const node = createBaseNode(SyntaxKind.ImportType); node.argument = argument; + node.assertions = assertion; node.qualifier = qualifier; node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); node.isTypeOf = isTypeOf; @@ -2047,12 +2064,28 @@ namespace ts { } // @api - function updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf = node.isTypeOf) { + function updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + function updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, assertions: ImportTypeAssertionContainer | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + function updateImportTypeNode( + node: ImportTypeNode, + argument: TypeNode, + qualifierOrAssertions: EntityName | ImportTypeAssertionContainer | undefined, + typeArgumentsOrQualifier: readonly TypeNode[] | EntityName | undefined, + isTypeOfOrTypeArguments: boolean | readonly TypeNode[] | undefined, + isTypeOf?: boolean | undefined + ) { + const assertion = qualifierOrAssertions && qualifierOrAssertions.kind === SyntaxKind.ImportTypeAssertionContainer ? qualifierOrAssertions : undefined; + const qualifier = qualifierOrAssertions && isEntityName(qualifierOrAssertions) ? qualifierOrAssertions + : typeArgumentsOrQualifier && !isArray(typeArgumentsOrQualifier) ? typeArgumentsOrQualifier : undefined; + const typeArguments = isArray(typeArgumentsOrQualifier) ? typeArgumentsOrQualifier : isArray(isTypeOfOrTypeArguments) ? isTypeOfOrTypeArguments : undefined; + isTypeOf = typeof isTypeOfOrTypeArguments === "boolean" ? isTypeOfOrTypeArguments : typeof isTypeOf === "boolean" ? isTypeOf : node.isTypeOf; + return node.argument !== argument + || node.assertions !== assertion || node.qualifier !== qualifier || node.typeArguments !== typeArguments || node.isTypeOf !== isTypeOf - ? update(createImportTypeNode(argument, qualifier, typeArguments, isTypeOf), node) + ? update(createImportTypeNode(argument, assertion, qualifier, typeArguments, isTypeOf), node) : node; } @@ -4040,6 +4073,22 @@ namespace ts { : node; } + // @api + function createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer { + const node = createBaseNode(SyntaxKind.ImportTypeAssertionContainer); + node.assertClause = clause; + node.multiLine = multiLine; + return node; + } + + // @api + function updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer { + return node.assertClause !== clause + || node.multiLine !== multiLine + ? update(createImportTypeAssertionContainer(clause, multiLine), node) + : node; + } + // @api function createNamespaceImport(name: Identifier): NamespaceImport { const node = createBaseNode(SyntaxKind.NamespaceImport); diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index d28e34a2bd7db..d8c21e054259f 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -102,7 +102,11 @@ namespace ts.moduleSpecifiers { const info = getInfo(importingSourceFile.path, host); const modulePaths = getAllModulePaths(importingSourceFile.path, nodeModulesFileName, host, preferences); return firstDefined(modulePaths, - modulePath => tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true)); + modulePath => tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true, getOverrideModeFromPreferences(preferences))); + } + + function getOverrideModeFromPreferences(preferences: UserPreferences) { + return preferences.overrideImportMode === "import" ? ModuleKind.ESNext : preferences.overrideImportMode === "require" ? ModuleKind.CommonJS : undefined; } function getModuleSpecifierWorker( @@ -116,7 +120,7 @@ namespace ts.moduleSpecifiers { ): string { const info = getInfo(importingSourceFileName, host); const modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences); - return firstDefined(modulePaths, modulePath => tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions)) || + return firstDefined(modulePaths, modulePath => tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ undefined, getOverrideModeFromPreferences(userPreferences))) || getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences); } @@ -210,6 +214,9 @@ namespace ts.moduleSpecifiers { host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)), reason => { if (reason.kind !== FileIncludeKind.Import || reason.file !== importingSourceFile.path) return undefined; + // If the candidate import mode doesn't match the mode we're generating for, don't consider it + // TODO: maybe useful to keep around as an alternative option for certain contexts where the mode is overridable + if (importingSourceFile.impliedNodeFormat && importingSourceFile.impliedNodeFormat !== getModeForResolutionAtIndex(importingSourceFile, reason.index)) return undefined; const specifier = getModuleNameStringLiteralAt(importingSourceFile, reason.index).text; // If the preference is for non relative and the module specifier is relative, ignore it return preferences.relativePreference !== RelativePreference.NonRelative || !pathIsRelative(specifier) ? @@ -233,7 +240,7 @@ namespace ts.moduleSpecifiers { let pathsSpecifiers: string[] | undefined; let relativeSpecifiers: string[] | undefined; for (const modulePath of modulePaths) { - const specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions); + const specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ undefined, getOverrideModeFromPreferences(userPreferences)); nodeModulesSpecifiers = append(nodeModulesSpecifiers, specifier); if (specifier && modulePath.isRedirect) { // If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar", @@ -650,7 +657,7 @@ namespace ts.moduleSpecifiers { : removeFileExtension(relativePath); } - function tryGetModuleNameAsNodeModule({ path, isRedirect }: ModulePath, { getCanonicalFileName, sourceDirectory }: Info, importingSourceFile: SourceFile , host: ModuleSpecifierResolutionHost, options: CompilerOptions, packageNameOnly?: boolean): string | undefined { + function tryGetModuleNameAsNodeModule({ path, isRedirect }: ModulePath, { getCanonicalFileName, sourceDirectory }: Info, importingSourceFile: SourceFile , host: ModuleSpecifierResolutionHost, options: CompilerOptions, packageNameOnly?: boolean, overrideMode?: ModuleKind.ESNext | ModuleKind.CommonJS): string | undefined { if (!host.fileExists || !host.readFile) { return undefined; } @@ -723,7 +730,7 @@ namespace ts.moduleSpecifiers { // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex` // with, so for now we just stick with the mode of the file. - const conditions = ["node", importingSourceFile.impliedNodeFormat === ModuleKind.ESNext ? "import" : "require", "types"]; + const conditions = ["node", overrideMode || importingSourceFile.impliedNodeFormat === ModuleKind.ESNext ? "import" : "require", "types"]; const fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions) : undefined; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f4f6e446cc1fa..2a9cb29e38c81 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -199,8 +199,11 @@ namespace ts { return visitNode(cbNode, (node as InferTypeNode).typeParameter); case SyntaxKind.ImportType: return visitNode(cbNode, (node as ImportTypeNode).argument) || + visitNode(cbNode, (node as ImportTypeNode).assertions) || visitNode(cbNode, (node as ImportTypeNode).qualifier) || visitNodes(cbNode, cbNodes, (node as ImportTypeNode).typeArguments); + case SyntaxKind.ImportTypeAssertionContainer: + return visitNode(cbNode, (node as ImportTypeAssertionContainer).assertClause); case SyntaxKind.ParenthesizedType: case SyntaxKind.TypeOperator: return visitNode(cbNode, (node as ParenthesizedTypeNode | TypeOperatorNode).type); @@ -3653,6 +3656,26 @@ namespace ts { return token() === SyntaxKind.ImportKeyword; } + function parseImportTypeAssertions(): ImportTypeAssertionContainer { + const pos = getNodePos(); + const openBracePosition = scanner.getTokenPos(); + parseExpected(SyntaxKind.OpenBraceToken); + const multiLine = scanner.hasPrecedingLineBreak(); + parseExpected(SyntaxKind.AssertKeyword); + parseExpected(SyntaxKind.ColonToken); + const clause = parseAssertClause(/*skipAssertKeyword*/ true); + if (!parseExpected(SyntaxKind.CloseBraceToken)) { + const lastError = lastOrUndefined(parseDiagnostics); + if (lastError && lastError.code === Diagnostics._0_expected.code) { + addRelatedInfo( + lastError, + createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here) + ); + } + } + return finishNode(factory.createImportTypeAssertionContainer(clause, multiLine), pos); + } + function parseImportType(): ImportTypeNode { sourceFlags |= NodeFlags.PossiblyContainsDynamicImport; const pos = getNodePos(); @@ -3660,10 +3683,14 @@ namespace ts { parseExpected(SyntaxKind.ImportKeyword); parseExpected(SyntaxKind.OpenParenToken); const type = parseType(); + let assertions: ImportTypeAssertionContainer | undefined; + if (parseOptional(SyntaxKind.CommaToken)) { + assertions = parseImportTypeAssertions(); + } parseExpected(SyntaxKind.CloseParenToken); const qualifier = parseOptional(SyntaxKind.DotToken) ? parseEntityNameOfTypeReference() : undefined; const typeArguments = parseTypeArgumentsOfTypeReference(); - return finishNode(factory.createImportTypeNode(type, qualifier, typeArguments, isTypeOf), pos); + return finishNode(factory.createImportTypeNode(type, assertions, qualifier, typeArguments, isTypeOf), pos); } function nextTokenIsNumericOrBigIntLiteral() { @@ -7285,9 +7312,11 @@ namespace ts { return finishNode(factory.createAssertEntry(name, value), pos); } - function parseAssertClause() { + function parseAssertClause(skipAssertKeyword?: true) { const pos = getNodePos(); - parseExpected(SyntaxKind.AssertKeyword); + if (!skipAssertKeyword) { + parseExpected(SyntaxKind.AssertKeyword); + } const openBracePosition = scanner.getTokenPos(); if (parseExpected(SyntaxKind.OpenBraceToken)) { const multiLine = scanner.hasPrecedingLineBreak(); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2ec4b292363f8..4a10f495f92aa 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -548,9 +548,39 @@ namespace ts { return getModeForUsageLocation(file, getModuleNameStringLiteralAt(file, index)); } + /* @internal */ + export function isExclusivelyTypeOnlyImportOrExport(decl: ImportDeclaration | ExportDeclaration) { + if (isExportDeclaration(decl)) { + return decl.isTypeOnly; + } + if (decl.importClause?.isTypeOnly) { + return true; + } + const bindings = decl.importClause?.namedBindings; + if (bindings && isNamedImports(bindings) && length(bindings.elements) && every(bindings.elements, b => b.isTypeOnly)) { + return true; + } + return false; + } + /* @internal */ export function getModeForUsageLocation(file: {impliedNodeFormat?: SourceFile["impliedNodeFormat"]}, usage: StringLiteralLike) { if (file.impliedNodeFormat === undefined) return undefined; + if ((isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent))) { + const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent); + if (isTypeOnly) { + const override = getResolutionModeOverrideForClause(usage.parent.assertClause); + if (override) { + return override; + } + } + } + if (usage.parent.parent && isImportTypeNode(usage.parent.parent)) { + const override = getResolutionModeOverrideForClause(usage.parent.parent.assertions?.assertClause); + if (override) { + return override; + } + } if (file.impliedNodeFormat !== ModuleKind.ESNext) { // in cjs files, import call expressions are esm format, otherwise everything is cjs return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? ModuleKind.ESNext : ModuleKind.CommonJS; @@ -561,6 +591,27 @@ namespace ts { return exprParentParent && isImportEqualsDeclaration(exprParentParent) ? ModuleKind.CommonJS : ModuleKind.ESNext; } + /* @internal */ + export function getResolutionModeOverrideForClause(clause: AssertClause | undefined, grammarErrorOnNode?: (node: Node, diagnostic: DiagnosticMessage) => boolean) { + if (!clause) return undefined; + if (length(clause.elements) !== 1) { + grammarErrorOnNode?.(clause, Diagnostics.Type_import_assertions_should_have_exactly_one_key_resolution_mode_with_value_import_or_require); + return undefined; + } + const elem = clause.elements[0]; + if (!isStringLiteralLike(elem.name)) return undefined; + if (elem.name.text !== "resolution-mode") { + grammarErrorOnNode?.(elem.name, Diagnostics.resolution_mode_is_the_only_valid_key_for_type_import_assertions); + return undefined; + } + if (!isStringLiteralLike(elem.value)) return undefined; + if (elem.value.text !== "import" && elem.value.text !== "require") { + grammarErrorOnNode?.(elem.value, Diagnostics.resolution_mode_should_be_either_require_or_import); + return undefined; + } + return elem.value.text === "import" ? ModuleKind.ESNext : ModuleKind.CommonJS; + } + /* @internal */ export function loadWithModeAwareCache(names: string[], containingFile: SourceFile, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined, loader: (name: string, resolverMode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined) => T): T[] { if (names.length === 0) { diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index f91ad7641d3ad..eae56dbaf1ae8 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -733,7 +733,7 @@ namespace ts { decl.modifiers, decl.importClause, rewriteModuleSpecifier(decl, decl.moduleSpecifier), - /*assertClause*/ undefined + getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined ); } // The `importClause` visibility corresponds to the default's visibility. @@ -745,7 +745,7 @@ namespace ts { decl.importClause.isTypeOnly, visibleDefaultBinding, /*namedBindings*/ undefined, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), /*assertClause*/ undefined); + ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined); } if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { // Namespace import (optionally with visible default) @@ -755,7 +755,7 @@ namespace ts { decl.importClause.isTypeOnly, visibleDefaultBinding, namedBindings, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), /*assertClause*/ undefined) : undefined; + ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined) : undefined; } // Named imports (optionally with visible default) const bindingList = mapDefined(decl.importClause.namedBindings.elements, b => resolver.isDeclarationVisible(b) ? b : undefined); @@ -771,7 +771,7 @@ namespace ts { bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined, ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), - /*assertClause*/ undefined + getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined ); } // Augmentation of export depends on import @@ -782,7 +782,7 @@ namespace ts { decl.modifiers, /*importClause*/ undefined, rewriteModuleSpecifier(decl, decl.moduleSpecifier), - /*assertClause*/ undefined + getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined ); } // Nothing visible @@ -1056,6 +1056,7 @@ namespace ts { return cleanup(factory.updateImportTypeNode( input, factory.updateLiteralTypeNode(input.argument, rewriteModuleSpecifier(input, input.argument.literal)), + input.assertions, input.qualifier, visitNodes(input.typeArguments, visitDeclarationSubtree, isTypeNode), input.isTypeOf @@ -1117,7 +1118,7 @@ namespace ts { input.isTypeOnly, input.exportClause, rewriteModuleSpecifier(input, input.moduleSpecifier), - /*assertClause*/ undefined + getResolutionModeOverrideForClause(input.assertClause) ? input.assertClause : undefined ); } case SyntaxKind.ExportAssignment: { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 928c082bb993b..d666517f30472 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -344,6 +344,7 @@ namespace ts { CatchClause, AssertClause, AssertEntry, + ImportTypeAssertionContainer, // Property assignments PropertyAssignment, @@ -1567,10 +1568,18 @@ namespace ts { readonly kind: TKind; } + export interface ImportTypeAssertionContainer extends Node { + readonly kind: SyntaxKind.ImportTypeAssertionContainer; + readonly parent: ImportTypeNode; + readonly assertClause: AssertClause; + readonly multiLine?: boolean; + } + export interface ImportTypeNode extends NodeWithTypeArguments { readonly kind: SyntaxKind.ImportType; readonly isTypeOf: boolean; readonly argument: TypeNode; + readonly assertions?: ImportTypeAssertionContainer; readonly qualifier?: EntityName; } @@ -7263,8 +7272,12 @@ namespace ts { updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode; createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode; updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode; + /*@deprecated*/ createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; + createImportTypeNode(argument: TypeNode, assertions?: ImportTypeAssertionContainer, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; + /*@deprecated*/ updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode; + updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, assertions: ImportTypeAssertionContainer | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode; createParenthesizedType(type: TypeNode): ParenthesizedTypeNode; updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; createThisTypeNode(): ThisTypeNode; @@ -7450,6 +7463,8 @@ namespace ts { updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; createAssertEntry(name: AssertionKey, value: Expression): AssertEntry; updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry; + createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer; + updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer; createNamespaceImport(name: Identifier): NamespaceImport; updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; createNamespaceExport(name: Identifier): NamespaceExport; @@ -8689,6 +8704,7 @@ namespace ts { readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; readonly jsxAttributeCompletionStyle?: "auto" | "braces" | "none"; + readonly overrideImportMode?: false | "require" | "import"; } /** Represents a bigint literal value without requiring bigint support */ diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 6ea7025031751..505db1dd5d4a1 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -592,11 +592,19 @@ namespace ts { Debug.type(node); return factory.updateImportTypeNode(node, nodeVisitor(node.argument, visitor, isTypeNode), + nodeVisitor(node.assertions, visitor, isNode), nodeVisitor(node.qualifier, visitor, isEntityName), visitNodes(node.typeArguments, visitor, isTypeNode), node.isTypeOf ); + case SyntaxKind.ImportTypeAssertionContainer: + Debug.type(node); + return factory.updateImportTypeAssertionContainer(node, + nodeVisitor(node.assertClause, visitor, isNode), + node.multiLine + ); + case SyntaxKind.NamedTupleMember: Debug.type(node); return factory.updateNamedTupleMember(node, diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 362eb1e253dee..5336704b82ccf 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -399,66 +399,67 @@ declare namespace ts { CatchClause = 291, AssertClause = 292, AssertEntry = 293, - PropertyAssignment = 294, - ShorthandPropertyAssignment = 295, - SpreadAssignment = 296, - EnumMember = 297, - UnparsedPrologue = 298, - UnparsedPrepend = 299, - UnparsedText = 300, - UnparsedInternalText = 301, - UnparsedSyntheticReference = 302, - SourceFile = 303, - Bundle = 304, - UnparsedSource = 305, - InputFiles = 306, - JSDocTypeExpression = 307, - JSDocNameReference = 308, - JSDocMemberName = 309, - JSDocAllType = 310, - JSDocUnknownType = 311, - JSDocNullableType = 312, - JSDocNonNullableType = 313, - JSDocOptionalType = 314, - JSDocFunctionType = 315, - JSDocVariadicType = 316, - JSDocNamepathType = 317, - JSDocComment = 318, - JSDocText = 319, - JSDocTypeLiteral = 320, - JSDocSignature = 321, - JSDocLink = 322, - JSDocLinkCode = 323, - JSDocLinkPlain = 324, - JSDocTag = 325, - JSDocAugmentsTag = 326, - JSDocImplementsTag = 327, - JSDocAuthorTag = 328, - JSDocDeprecatedTag = 329, - JSDocClassTag = 330, - JSDocPublicTag = 331, - JSDocPrivateTag = 332, - JSDocProtectedTag = 333, - JSDocReadonlyTag = 334, - JSDocOverrideTag = 335, - JSDocCallbackTag = 336, - JSDocEnumTag = 337, - JSDocParameterTag = 338, - JSDocReturnTag = 339, - JSDocThisTag = 340, - JSDocTypeTag = 341, - JSDocTemplateTag = 342, - JSDocTypedefTag = 343, - JSDocSeeTag = 344, - JSDocPropertyTag = 345, - SyntaxList = 346, - NotEmittedStatement = 347, - PartiallyEmittedExpression = 348, - CommaListExpression = 349, - MergeDeclarationMarker = 350, - EndOfDeclarationMarker = 351, - SyntheticReferenceExpression = 352, - Count = 353, + ImportTypeAssertionContainer = 294, + PropertyAssignment = 295, + ShorthandPropertyAssignment = 296, + SpreadAssignment = 297, + EnumMember = 298, + UnparsedPrologue = 299, + UnparsedPrepend = 300, + UnparsedText = 301, + UnparsedInternalText = 302, + UnparsedSyntheticReference = 303, + SourceFile = 304, + Bundle = 305, + UnparsedSource = 306, + InputFiles = 307, + JSDocTypeExpression = 308, + JSDocNameReference = 309, + JSDocMemberName = 310, + JSDocAllType = 311, + JSDocUnknownType = 312, + JSDocNullableType = 313, + JSDocNonNullableType = 314, + JSDocOptionalType = 315, + JSDocFunctionType = 316, + JSDocVariadicType = 317, + JSDocNamepathType = 318, + JSDocComment = 319, + JSDocText = 320, + JSDocTypeLiteral = 321, + JSDocSignature = 322, + JSDocLink = 323, + JSDocLinkCode = 324, + JSDocLinkPlain = 325, + JSDocTag = 326, + JSDocAugmentsTag = 327, + JSDocImplementsTag = 328, + JSDocAuthorTag = 329, + JSDocDeprecatedTag = 330, + JSDocClassTag = 331, + JSDocPublicTag = 332, + JSDocPrivateTag = 333, + JSDocProtectedTag = 334, + JSDocReadonlyTag = 335, + JSDocOverrideTag = 336, + JSDocCallbackTag = 337, + JSDocEnumTag = 338, + JSDocParameterTag = 339, + JSDocReturnTag = 340, + JSDocThisTag = 341, + JSDocTypeTag = 342, + JSDocTemplateTag = 343, + JSDocTypedefTag = 344, + JSDocSeeTag = 345, + JSDocPropertyTag = 346, + SyntaxList = 347, + NotEmittedStatement = 348, + PartiallyEmittedExpression = 349, + CommaListExpression = 350, + MergeDeclarationMarker = 351, + EndOfDeclarationMarker = 352, + SyntheticReferenceExpression = 353, + Count = 354, FirstAssignment = 63, LastAssignment = 78, FirstCompoundAssignment = 64, @@ -486,10 +487,10 @@ declare namespace ts { FirstStatement = 236, LastStatement = 252, FirstNode = 160, - FirstJSDocNode = 307, - LastJSDocNode = 345, - FirstJSDocTagNode = 325, - LastJSDocTagNode = 345, + FirstJSDocNode = 308, + LastJSDocNode = 346, + FirstJSDocTagNode = 326, + LastJSDocTagNode = 346, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; @@ -866,10 +867,17 @@ declare namespace ts { export interface KeywordTypeNode extends KeywordToken, TypeNode { readonly kind: TKind; } + export interface ImportTypeAssertionContainer extends Node { + readonly kind: SyntaxKind.ImportTypeAssertionContainer; + readonly parent: ImportTypeNode; + readonly assertClause: AssertClause; + readonly multiLine?: boolean; + } export interface ImportTypeNode extends NodeWithTypeArguments { readonly kind: SyntaxKind.ImportType; readonly isTypeOf: boolean; readonly argument: TypeNode; + readonly assertions?: ImportTypeAssertionContainer; readonly qualifier?: EntityName; } export interface ThisTypeNode extends TypeNode { @@ -3420,7 +3428,9 @@ declare namespace ts { createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode; updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode; createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; + createImportTypeNode(argument: TypeNode, assertions?: ImportTypeAssertionContainer, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode; + updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, assertions: ImportTypeAssertionContainer | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode; createParenthesizedType(type: TypeNode): ParenthesizedTypeNode; updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; createThisTypeNode(): ThisTypeNode; @@ -3583,6 +3593,8 @@ declare namespace ts { updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; createAssertEntry(name: AssertionKey, value: Expression): AssertEntry; updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry; + createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer; + updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer; createNamespaceImport(name: Identifier): NamespaceImport; updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; createNamespaceExport(name: Identifier): NamespaceExport; @@ -4058,6 +4070,7 @@ declare namespace ts { readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; readonly jsxAttributeCompletionStyle?: "auto" | "braces" | "none"; + readonly overrideImportMode?: false | "require" | "import"; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -10790,9 +10803,15 @@ declare namespace ts { /** @deprecated Use `factory.updateInferTypeNode` or the factory supplied by your transformation context instead. */ const updateInferTypeNode: (node: InferTypeNode, typeParameter: TypeParameterDeclaration) => InferTypeNode; /** @deprecated Use `factory.createImportTypeNode` or the factory supplied by your transformation context instead. */ - const createImportTypeNode: (argument: TypeNode, qualifier?: EntityName | undefined, typeArguments?: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined) => ImportTypeNode; + const createImportTypeNode: { + (argument: TypeNode, qualifier?: EntityName | undefined, typeArguments?: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + (argument: TypeNode, assertions?: ImportTypeAssertionContainer | undefined, qualifier?: EntityName | undefined, typeArguments?: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + }; /** @deprecated Use `factory.updateImportTypeNode` or the factory supplied by your transformation context instead. */ - const updateImportTypeNode: (node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined) => ImportTypeNode; + const updateImportTypeNode: { + (node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + (node: ImportTypeNode, argument: TypeNode, assertions: ImportTypeAssertionContainer | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + }; /** @deprecated Use `factory.createParenthesizedType` or the factory supplied by your transformation context instead. */ const createParenthesizedType: (type: TypeNode) => ParenthesizedTypeNode; /** @deprecated Use `factory.updateParenthesizedType` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 38c8f49925770..afcd586f01814 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -399,66 +399,67 @@ declare namespace ts { CatchClause = 291, AssertClause = 292, AssertEntry = 293, - PropertyAssignment = 294, - ShorthandPropertyAssignment = 295, - SpreadAssignment = 296, - EnumMember = 297, - UnparsedPrologue = 298, - UnparsedPrepend = 299, - UnparsedText = 300, - UnparsedInternalText = 301, - UnparsedSyntheticReference = 302, - SourceFile = 303, - Bundle = 304, - UnparsedSource = 305, - InputFiles = 306, - JSDocTypeExpression = 307, - JSDocNameReference = 308, - JSDocMemberName = 309, - JSDocAllType = 310, - JSDocUnknownType = 311, - JSDocNullableType = 312, - JSDocNonNullableType = 313, - JSDocOptionalType = 314, - JSDocFunctionType = 315, - JSDocVariadicType = 316, - JSDocNamepathType = 317, - JSDocComment = 318, - JSDocText = 319, - JSDocTypeLiteral = 320, - JSDocSignature = 321, - JSDocLink = 322, - JSDocLinkCode = 323, - JSDocLinkPlain = 324, - JSDocTag = 325, - JSDocAugmentsTag = 326, - JSDocImplementsTag = 327, - JSDocAuthorTag = 328, - JSDocDeprecatedTag = 329, - JSDocClassTag = 330, - JSDocPublicTag = 331, - JSDocPrivateTag = 332, - JSDocProtectedTag = 333, - JSDocReadonlyTag = 334, - JSDocOverrideTag = 335, - JSDocCallbackTag = 336, - JSDocEnumTag = 337, - JSDocParameterTag = 338, - JSDocReturnTag = 339, - JSDocThisTag = 340, - JSDocTypeTag = 341, - JSDocTemplateTag = 342, - JSDocTypedefTag = 343, - JSDocSeeTag = 344, - JSDocPropertyTag = 345, - SyntaxList = 346, - NotEmittedStatement = 347, - PartiallyEmittedExpression = 348, - CommaListExpression = 349, - MergeDeclarationMarker = 350, - EndOfDeclarationMarker = 351, - SyntheticReferenceExpression = 352, - Count = 353, + ImportTypeAssertionContainer = 294, + PropertyAssignment = 295, + ShorthandPropertyAssignment = 296, + SpreadAssignment = 297, + EnumMember = 298, + UnparsedPrologue = 299, + UnparsedPrepend = 300, + UnparsedText = 301, + UnparsedInternalText = 302, + UnparsedSyntheticReference = 303, + SourceFile = 304, + Bundle = 305, + UnparsedSource = 306, + InputFiles = 307, + JSDocTypeExpression = 308, + JSDocNameReference = 309, + JSDocMemberName = 310, + JSDocAllType = 311, + JSDocUnknownType = 312, + JSDocNullableType = 313, + JSDocNonNullableType = 314, + JSDocOptionalType = 315, + JSDocFunctionType = 316, + JSDocVariadicType = 317, + JSDocNamepathType = 318, + JSDocComment = 319, + JSDocText = 320, + JSDocTypeLiteral = 321, + JSDocSignature = 322, + JSDocLink = 323, + JSDocLinkCode = 324, + JSDocLinkPlain = 325, + JSDocTag = 326, + JSDocAugmentsTag = 327, + JSDocImplementsTag = 328, + JSDocAuthorTag = 329, + JSDocDeprecatedTag = 330, + JSDocClassTag = 331, + JSDocPublicTag = 332, + JSDocPrivateTag = 333, + JSDocProtectedTag = 334, + JSDocReadonlyTag = 335, + JSDocOverrideTag = 336, + JSDocCallbackTag = 337, + JSDocEnumTag = 338, + JSDocParameterTag = 339, + JSDocReturnTag = 340, + JSDocThisTag = 341, + JSDocTypeTag = 342, + JSDocTemplateTag = 343, + JSDocTypedefTag = 344, + JSDocSeeTag = 345, + JSDocPropertyTag = 346, + SyntaxList = 347, + NotEmittedStatement = 348, + PartiallyEmittedExpression = 349, + CommaListExpression = 350, + MergeDeclarationMarker = 351, + EndOfDeclarationMarker = 352, + SyntheticReferenceExpression = 353, + Count = 354, FirstAssignment = 63, LastAssignment = 78, FirstCompoundAssignment = 64, @@ -486,10 +487,10 @@ declare namespace ts { FirstStatement = 236, LastStatement = 252, FirstNode = 160, - FirstJSDocNode = 307, - LastJSDocNode = 345, - FirstJSDocTagNode = 325, - LastJSDocTagNode = 345, + FirstJSDocNode = 308, + LastJSDocNode = 346, + FirstJSDocTagNode = 326, + LastJSDocTagNode = 346, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; @@ -866,10 +867,17 @@ declare namespace ts { export interface KeywordTypeNode extends KeywordToken, TypeNode { readonly kind: TKind; } + export interface ImportTypeAssertionContainer extends Node { + readonly kind: SyntaxKind.ImportTypeAssertionContainer; + readonly parent: ImportTypeNode; + readonly assertClause: AssertClause; + readonly multiLine?: boolean; + } export interface ImportTypeNode extends NodeWithTypeArguments { readonly kind: SyntaxKind.ImportType; readonly isTypeOf: boolean; readonly argument: TypeNode; + readonly assertions?: ImportTypeAssertionContainer; readonly qualifier?: EntityName; } export interface ThisTypeNode extends TypeNode { @@ -3420,7 +3428,9 @@ declare namespace ts { createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode; updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode; createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; + createImportTypeNode(argument: TypeNode, assertions?: ImportTypeAssertionContainer, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode; + updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, assertions: ImportTypeAssertionContainer | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode; createParenthesizedType(type: TypeNode): ParenthesizedTypeNode; updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; createThisTypeNode(): ThisTypeNode; @@ -3583,6 +3593,8 @@ declare namespace ts { updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; createAssertEntry(name: AssertionKey, value: Expression): AssertEntry; updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry; + createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer; + updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer; createNamespaceImport(name: Identifier): NamespaceImport; updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; createNamespaceExport(name: Identifier): NamespaceExport; @@ -4058,6 +4070,7 @@ declare namespace ts { readonly includePackageJsonAutoImports?: "auto" | "on" | "off"; readonly provideRefactorNotApplicableReason?: boolean; readonly jsxAttributeCompletionStyle?: "auto" | "braces" | "none"; + readonly overrideImportMode?: false | "require" | "import"; } /** Represents a bigint literal value without requiring bigint support */ export interface PseudoBigInt { @@ -6979,9 +6992,15 @@ declare namespace ts { /** @deprecated Use `factory.updateInferTypeNode` or the factory supplied by your transformation context instead. */ const updateInferTypeNode: (node: InferTypeNode, typeParameter: TypeParameterDeclaration) => InferTypeNode; /** @deprecated Use `factory.createImportTypeNode` or the factory supplied by your transformation context instead. */ - const createImportTypeNode: (argument: TypeNode, qualifier?: EntityName | undefined, typeArguments?: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined) => ImportTypeNode; + const createImportTypeNode: { + (argument: TypeNode, qualifier?: EntityName | undefined, typeArguments?: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + (argument: TypeNode, assertions?: ImportTypeAssertionContainer | undefined, qualifier?: EntityName | undefined, typeArguments?: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + }; /** @deprecated Use `factory.updateImportTypeNode` or the factory supplied by your transformation context instead. */ - const updateImportTypeNode: (node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined) => ImportTypeNode; + const updateImportTypeNode: { + (node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + (node: ImportTypeNode, argument: TypeNode, assertions: ImportTypeAssertionContainer | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined): ImportTypeNode; + }; /** @deprecated Use `factory.createParenthesizedType` or the factory supplied by your transformation context instead. */ const createParenthesizedType: (type: TypeNode) => ParenthesizedTypeNode; /** @deprecated Use `factory.updateParenthesizedType` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js index f8d6161af5772..9bc4bb789c561 100644 --- a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js @@ -155,10 +155,10 @@ export declare const d: { export declare const e: typeof import("inner/mjs"); //// [other.d.cts] export declare const a: Promise<{ - default: typeof import("package/cjs"); + default: typeof import("./index.cjs"); }>; -export declare const b: Promise; -export declare const c: Promise; +export declare const b: Promise; +export declare const c: Promise; export declare const f: Promise<{ default: typeof import("inner"); cjsMain: true; @@ -168,113 +168,4 @@ export declare const d: Promise<{ default: typeof import("inner/cjs"); cjsNonmain: true; }>; -export declare const e: Promise; - - -//// [DtsFileErrors] - - -tests/cases/conformance/node/other.d.cts(4,47): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/other.d.cts(5,47): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/other2.d.cts(5,47): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. - - -==== tests/cases/conformance/node/index.d.ts (0 errors) ==== - export {}; - -==== tests/cases/conformance/node/index.d.mts (0 errors) ==== - export {}; - -==== tests/cases/conformance/node/index.d.cts (0 errors) ==== - export {}; - -==== tests/cases/conformance/node/other.d.ts (0 errors) ==== - export declare const a: { - default: typeof import("package/cjs"); - }; - export declare const b: typeof import("package/mjs"); - export declare const c: typeof import("package"); - export declare const f: { - default: typeof import("inner"); - cjsMain: true; - }; - -==== tests/cases/conformance/node/other2.d.ts (0 errors) ==== - export declare const d: { - default: typeof import("inner/cjs"); - cjsNonmain: true; - }; - export declare const e: typeof import("inner/mjs"); - -==== tests/cases/conformance/node/other.d.mts (0 errors) ==== - export declare const a: { - default: typeof import("package/cjs"); - }; - export declare const b: typeof import("package/mjs"); - export declare const c: typeof import("package"); - export declare const f: { - default: typeof import("inner"); - cjsMain: true; - }; - -==== tests/cases/conformance/node/other2.d.mts (0 errors) ==== - export declare const d: { - default: typeof import("inner/cjs"); - cjsNonmain: true; - }; - export declare const e: typeof import("inner/mjs"); - -==== tests/cases/conformance/node/other.d.cts (2 errors) ==== - export declare const a: Promise<{ - default: typeof import("package/cjs"); - }>; - export declare const b: Promise; - ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. - export declare const c: Promise; - ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. - export declare const f: Promise<{ - default: typeof import("inner"); - cjsMain: true; - }>; - -==== tests/cases/conformance/node/other2.d.cts (1 errors) ==== - export declare const d: Promise<{ - default: typeof import("inner/cjs"); - cjsNonmain: true; - }>; - export declare const e: Promise; - ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. - -==== tests/cases/conformance/node/node_modules/inner/index.d.ts (0 errors) ==== - // cjs format file - export const cjsMain = true; -==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== - // esm format file - export const esm = true; -==== tests/cases/conformance/node/node_modules/inner/index.d.cts (0 errors) ==== - // cjs format file - export const cjsNonmain = true; -==== tests/cases/conformance/node/package.json (0 errors) ==== - { - "name": "package", - "private": true, - "type": "module", - "exports": { - "./cjs": "./index.cjs", - "./mjs": "./index.mjs", - ".": "./index.js" - } - } -==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ==== - { - "name": "inner", - "private": true, - "exports": { - "./cjs": "./index.cjs", - "./mjs": "./index.mjs", - ".": "./index.js" - } - } \ No newline at end of file +export declare const e: Promise; diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.types b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.types index 54a78d6a9fc2e..38a4e474dc632 100644 --- a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.types +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.types @@ -95,13 +95,13 @@ export const a = import("package/cjs"); >"package/cjs" : "package/cjs" export const b = import("package/mjs"); ->b : Promise ->import("package/mjs") : Promise +>b : Promise +>import("package/mjs") : Promise >"package/mjs" : "package/mjs" export const c = import("package"); ->c : Promise ->import("package") : Promise +>c : Promise +>import("package") : Promise >"package" : "package" export const f = import("inner"); @@ -117,8 +117,8 @@ export const d = import("inner/cjs"); >"inner/cjs" : "inner/cjs" export const e = import("inner/mjs"); ->e : Promise ->import("inner/mjs") : Promise +>e : Promise +>import("inner/mjs") : Promise >"inner/mjs" : "inner/mjs" === tests/cases/conformance/node/node_modules/inner/index.d.ts === diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node12).js b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node12).js new file mode 100644 index 0000000000000..1b8bc65976edc --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node12).js @@ -0,0 +1,45 @@ +//// [tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit1.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [index.ts] +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + + +//// [index.d.ts] +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +export interface LocalInterface extends RequireInterface, ImportInterface { +} +import { type RequireInterface as Req } from "pkg" assert { "resolution-mode": "require" }; +import { type ImportInterface as Imp } from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp { +} +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node12).symbols b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node12).symbols new file mode 100644 index 0000000000000..4df3228fa27c9 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node12).symbols @@ -0,0 +1,39 @@ +=== /index.ts === +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 0, 13)) + +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 1, 13)) + +export interface LocalInterface extends RequireInterface, ImportInterface {} +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 1, 82)) +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 0, 13)) +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 1, 13)) + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) + +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) +>Imp : Symbol(Imp, Decl(index.ts, 6, 8)) + +export interface Loc extends Req, Imp {} +>Loc : Symbol(Loc, Decl(index.ts, 6, 87)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) +>Imp : Symbol(Imp, Decl(index.ts, 6, 8)) + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 9, 13)) + +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 10, 13)) + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node12).types b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node12).types new file mode 100644 index 0000000000000..61190a772be06 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node12).types @@ -0,0 +1,30 @@ +=== /index.ts === +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : RequireInterface + +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : ImportInterface + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : any +>Req : any + +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : any +>Imp : any + +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : RequireInterface + +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : ImportInterface + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +No type information for this code.=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).js b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).js new file mode 100644 index 0000000000000..1b8bc65976edc --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).js @@ -0,0 +1,45 @@ +//// [tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit1.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [index.ts] +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + + +//// [index.d.ts] +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +export interface LocalInterface extends RequireInterface, ImportInterface { +} +import { type RequireInterface as Req } from "pkg" assert { "resolution-mode": "require" }; +import { type ImportInterface as Imp } from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp { +} +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).symbols b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).symbols new file mode 100644 index 0000000000000..4df3228fa27c9 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).symbols @@ -0,0 +1,39 @@ +=== /index.ts === +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 0, 13)) + +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 1, 13)) + +export interface LocalInterface extends RequireInterface, ImportInterface {} +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 1, 82)) +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 0, 13)) +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 1, 13)) + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) + +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) +>Imp : Symbol(Imp, Decl(index.ts, 6, 8)) + +export interface Loc extends Req, Imp {} +>Loc : Symbol(Loc, Decl(index.ts, 6, 87)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) +>Imp : Symbol(Imp, Decl(index.ts, 6, 8)) + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 9, 13)) + +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 10, 13)) + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).types b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).types new file mode 100644 index 0000000000000..61190a772be06 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).types @@ -0,0 +1,30 @@ +=== /index.ts === +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : RequireInterface + +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : ImportInterface + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : any +>Req : any + +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : any +>Imp : any + +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : RequireInterface + +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : ImportInterface + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +No type information for this code.=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node12).js b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node12).js new file mode 100644 index 0000000000000..fad19d466a6ac --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node12).js @@ -0,0 +1,49 @@ +//// [tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit2.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [package.json] +{ + "private": true, + "type": "module" +} +//// [index.ts] +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + + +//// [index.js] +export {}; + + +//// [index.d.ts] +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +export interface LocalInterface extends RequireInterface, ImportInterface { +} +import { type RequireInterface as Req } from "pkg" assert { "resolution-mode": "require" }; +import { type ImportInterface as Imp } from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp { +} +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node12).symbols b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node12).symbols new file mode 100644 index 0000000000000..4df3228fa27c9 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node12).symbols @@ -0,0 +1,39 @@ +=== /index.ts === +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 0, 13)) + +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 1, 13)) + +export interface LocalInterface extends RequireInterface, ImportInterface {} +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 1, 82)) +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 0, 13)) +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 1, 13)) + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) + +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) +>Imp : Symbol(Imp, Decl(index.ts, 6, 8)) + +export interface Loc extends Req, Imp {} +>Loc : Symbol(Loc, Decl(index.ts, 6, 87)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) +>Imp : Symbol(Imp, Decl(index.ts, 6, 8)) + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 9, 13)) + +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 10, 13)) + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node12).types b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node12).types new file mode 100644 index 0000000000000..61190a772be06 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node12).types @@ -0,0 +1,30 @@ +=== /index.ts === +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : RequireInterface + +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : ImportInterface + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : any +>Req : any + +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : any +>Imp : any + +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : RequireInterface + +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : ImportInterface + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +No type information for this code.=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).js b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).js new file mode 100644 index 0000000000000..fad19d466a6ac --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).js @@ -0,0 +1,49 @@ +//// [tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit2.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [package.json] +{ + "private": true, + "type": "module" +} +//// [index.ts] +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + + +//// [index.js] +export {}; + + +//// [index.d.ts] +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +export interface LocalInterface extends RequireInterface, ImportInterface { +} +import { type RequireInterface as Req } from "pkg" assert { "resolution-mode": "require" }; +import { type ImportInterface as Imp } from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp { +} +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).symbols b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).symbols new file mode 100644 index 0000000000000..4df3228fa27c9 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).symbols @@ -0,0 +1,39 @@ +=== /index.ts === +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 0, 13)) + +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 1, 13)) + +export interface LocalInterface extends RequireInterface, ImportInterface {} +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 1, 82)) +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 0, 13)) +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 1, 13)) + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) + +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) +>Imp : Symbol(Imp, Decl(index.ts, 6, 8)) + +export interface Loc extends Req, Imp {} +>Loc : Symbol(Loc, Decl(index.ts, 6, 87)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) +>Imp : Symbol(Imp, Decl(index.ts, 6, 8)) + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 9, 13)) + +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 10, 13)) + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).types b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).types new file mode 100644 index 0000000000000..61190a772be06 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).types @@ -0,0 +1,30 @@ +=== /index.ts === +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : RequireInterface + +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : ImportInterface + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : any +>Req : any + +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : any +>Imp : any + +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : RequireInterface + +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : ImportInterface + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +No type information for this code.=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).errors.txt b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).errors.txt new file mode 100644 index 0000000000000..bc3eb30565c6f --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).errors.txt @@ -0,0 +1,43 @@ +/index.ts(2,45): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. +/index.ts(2,73): error TS1453: `resolution-mode` should be either `require` or `import`. +/index.ts(4,10): error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. +/index.ts(4,39): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. +/index.ts(6,76): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. + + +==== /index.ts (5 errors) ==== + // incorrect mode + import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. + ~~~~~~~~ +!!! error TS1453: `resolution-mode` should be either `require` or `import`. + // not type-only + import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + ~~~~~~~~~~~~~~~ +!!! error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. + // not exclusively type-only + import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. + + export interface LocalInterface extends RequireInterface, ImportInterface {} + + + + +==== /node_modules/pkg/package.json (0 errors) ==== + { + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } + } +==== /node_modules/pkg/import.d.ts (0 errors) ==== + export interface ImportInterface {} +==== /node_modules/pkg/require.d.ts (0 errors) ==== + export interface RequireInterface {} \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).js b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).js new file mode 100644 index 0000000000000..3b2af2656d08b --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).js @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/node/nodeModulesImportModeDeclarationEmitErrors1.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [index.ts] +// incorrect mode +import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" }; +// not type-only +import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +// not exclusively type-only +import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; + +export interface LocalInterface extends RequireInterface, ImportInterface {} + + + + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + + +//// [index.d.ts] +import type { RequireInterface } from "pkg"; +import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +export interface LocalInterface extends RequireInterface, ImportInterface { +} diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).symbols b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).symbols new file mode 100644 index 0000000000000..fd1457831835d --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).symbols @@ -0,0 +1,28 @@ +=== /index.ts === +// incorrect mode +import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 1, 13)) + +// not type-only +import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 3, 8)) + +// not exclusively type-only +import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) +>Req2 : Symbol(Req2, Decl(index.ts, 5, 37)) + +export interface LocalInterface extends RequireInterface, ImportInterface {} +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 5, 115)) +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 1, 13)) +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 3, 8)) + + + + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).types b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).types new file mode 100644 index 0000000000000..07bda5323dbc8 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node12).types @@ -0,0 +1,24 @@ +=== /index.ts === +// incorrect mode +import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" }; +>RequireInterface : RequireInterface + +// not type-only +import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : any + +// not exclusively type-only +import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : any +>Req : any +>RequireInterface : any +>Req2 : any + +export interface LocalInterface extends RequireInterface, ImportInterface {} + + + + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).errors.txt new file mode 100644 index 0000000000000..49a86cf598055 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).errors.txt @@ -0,0 +1,43 @@ +/index.ts(2,45): error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. +/index.ts(2,73): error TS1453: `resolution-mode` should be either `require` or `import`. +/index.ts(4,10): error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. +/index.ts(4,39): error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. +/index.ts(6,76): error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. + + +==== /index.ts (5 errors) ==== + // incorrect mode + import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. + ~~~~~~~~ +!!! error TS1453: `resolution-mode` should be either `require` or `import`. + // not type-only + import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + ~~~~~~~~~~~~~~~ +!!! error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. + // not exclusively type-only + import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. + + export interface LocalInterface extends RequireInterface, ImportInterface {} + + + + +==== /node_modules/pkg/package.json (0 errors) ==== + { + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } + } +==== /node_modules/pkg/import.d.ts (0 errors) ==== + export interface ImportInterface {} +==== /node_modules/pkg/require.d.ts (0 errors) ==== + export interface RequireInterface {} \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).js b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).js new file mode 100644 index 0000000000000..3b2af2656d08b --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).js @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/node/nodeModulesImportModeDeclarationEmitErrors1.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [index.ts] +// incorrect mode +import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" }; +// not type-only +import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +// not exclusively type-only +import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; + +export interface LocalInterface extends RequireInterface, ImportInterface {} + + + + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + + +//// [index.d.ts] +import type { RequireInterface } from "pkg"; +import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +export interface LocalInterface extends RequireInterface, ImportInterface { +} diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).symbols b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).symbols new file mode 100644 index 0000000000000..fd1457831835d --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).symbols @@ -0,0 +1,28 @@ +=== /index.ts === +// incorrect mode +import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" }; +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 1, 13)) + +// not type-only +import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 3, 8)) + +// not exclusively type-only +import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) +>Req : Symbol(Req, Decl(index.ts, 5, 8)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) +>Req2 : Symbol(Req2, Decl(index.ts, 5, 37)) + +export interface LocalInterface extends RequireInterface, ImportInterface {} +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 5, 115)) +>RequireInterface : Symbol(RequireInterface, Decl(index.ts, 1, 13)) +>ImportInterface : Symbol(ImportInterface, Decl(index.ts, 3, 8)) + + + + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).types b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).types new file mode 100644 index 0000000000000..07bda5323dbc8 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).types @@ -0,0 +1,24 @@ +=== /index.ts === +// incorrect mode +import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" }; +>RequireInterface : RequireInterface + +// not type-only +import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +>ImportInterface : any + +// not exclusively type-only +import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; +>RequireInterface : any +>Req : any +>RequireInterface : any +>Req2 : any + +export interface LocalInterface extends RequireInterface, ImportInterface {} + + + + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node12).js b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node12).js new file mode 100644 index 0000000000000..4a65e05cdd90e --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node12).js @@ -0,0 +1,36 @@ +//// [tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmit1.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [index.ts] +export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = null; +exports.b = null; + + +//// [index.d.ts] +export declare type LocalInterface = import("pkg", { assert: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; +export declare const a: import("pkg").RequireInterface; +export declare const b: import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node12).symbols b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node12).symbols new file mode 100644 index 0000000000000..dd5d452777292 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node12).symbols @@ -0,0 +1,26 @@ +=== /index.ts === +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface); +>a : Symbol(a, Decl(index.ts, 4, 12)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +>b : Symbol(b, Decl(index.ts, 5, 12)) +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node12).types b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node12).types new file mode 100644 index 0000000000000..82a46bf9b274c --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node12).types @@ -0,0 +1,26 @@ +=== /index.ts === +export type LocalInterface = +>LocalInterface : LocalInterface + + & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface); +>a : import("/node_modules/pkg/require").RequireInterface +>(null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface) : import("/node_modules/pkg/require").RequireInterface +>null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface : import("/node_modules/pkg/require").RequireInterface +>null as any : any +>null : null + +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +>b : import("/node_modules/pkg/import").ImportInterface +>(null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface) : import("/node_modules/pkg/import").ImportInterface +>null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface : import("/node_modules/pkg/import").ImportInterface +>null as any : any +>null : null + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +No type information for this code.=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).js b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).js new file mode 100644 index 0000000000000..4a65e05cdd90e --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).js @@ -0,0 +1,36 @@ +//// [tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmit1.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [index.ts] +export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = null; +exports.b = null; + + +//// [index.d.ts] +export declare type LocalInterface = import("pkg", { assert: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; +export declare const a: import("pkg").RequireInterface; +export declare const b: import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).symbols b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).symbols new file mode 100644 index 0000000000000..dd5d452777292 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).symbols @@ -0,0 +1,26 @@ +=== /index.ts === +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface); +>a : Symbol(a, Decl(index.ts, 4, 12)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +>b : Symbol(b, Decl(index.ts, 5, 12)) +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).types b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).types new file mode 100644 index 0000000000000..82a46bf9b274c --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).types @@ -0,0 +1,26 @@ +=== /index.ts === +export type LocalInterface = +>LocalInterface : LocalInterface + + & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface); +>a : import("/node_modules/pkg/require").RequireInterface +>(null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface) : import("/node_modules/pkg/require").RequireInterface +>null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface : import("/node_modules/pkg/require").RequireInterface +>null as any : any +>null : null + +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +>b : import("/node_modules/pkg/import").ImportInterface +>(null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface) : import("/node_modules/pkg/import").ImportInterface +>null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface : import("/node_modules/pkg/import").ImportInterface +>null as any : any +>null : null + +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +No type information for this code.=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).errors.txt b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).errors.txt new file mode 100644 index 0000000000000..1159c2b965e3f --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).errors.txt @@ -0,0 +1,304 @@ +/index.ts(2,51): error TS1453: `resolution-mode` should be either `require` or `import`. +/index.ts(5,78): error TS1453: `resolution-mode` should be either `require` or `import`. +/other.ts(3,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other.ts(3,22): error TS1005: 'assert' expected. +/other.ts(3,39): error TS1005: ';' expected. +/other.ts(3,50): error TS1128: Declaration or statement expected. +/other.ts(3,51): error TS1128: Declaration or statement expected. +/other.ts(3,52): error TS1128: Declaration or statement expected. +/other.ts(3,53): error TS2304: Cannot find name 'RequireInterface'. +/other.ts(4,22): error TS2322: Type '{ "resolution-mode": string; }' is not assignable to type 'ImportCallOptions'. + Object literal may only specify known properties, and '"resolution-mode"' does not exist in type 'ImportCallOptions'. +/other.ts(4,52): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. +/other.ts(6,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other.ts(6,49): error TS1005: 'assert' expected. +/other.ts(6,66): error TS1005: ';' expected. +/other.ts(6,77): error TS1128: Declaration or statement expected. +/other.ts(6,78): error TS1128: Declaration or statement expected. +/other.ts(6,79): error TS1128: Declaration or statement expected. +/other.ts(6,80): error TS1434: Unexpected keyword or identifier. +/other.ts(6,80): error TS2304: Cannot find name 'RequireInterface'. +/other.ts(6,96): error TS1128: Declaration or statement expected. +/other.ts(7,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other.ts(7,49): error TS1005: 'assert' expected. +/other.ts(7,66): error TS1005: ';' expected. +/other.ts(7,76): error TS1128: Declaration or statement expected. +/other.ts(7,77): error TS1128: Declaration or statement expected. +/other.ts(7,78): error TS1128: Declaration or statement expected. +/other.ts(7,79): error TS1434: Unexpected keyword or identifier. +/other.ts(7,79): error TS2304: Cannot find name 'ImportInterface'. +/other.ts(7,94): error TS1128: Declaration or statement expected. +/other2.ts(3,32): error TS1455: `resolution-mode` is the only valid key for type import assertions. +/other2.ts(4,32): error TS1455: `resolution-mode` is the only valid key for type import assertions. +/other2.ts(4,64): error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. +/other2.ts(6,59): error TS1455: `resolution-mode` is the only valid key for type import assertions. +/other2.ts(7,59): error TS1455: `resolution-mode` is the only valid key for type import assertions. +/other2.ts(7,91): error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. +/other3.ts(3,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other3.ts(3,21): error TS1005: '{' expected. +/other3.ts(3,23): error TS2538: Type '{ "resolution-mode": "require"; }' cannot be used as an index type. +/other3.ts(3,55): error TS1005: ';' expected. +/other3.ts(3,56): error TS1128: Declaration or statement expected. +/other3.ts(3,57): error TS2304: Cannot find name 'RequireInterface'. +/other3.ts(4,21): error TS2559: Type '{ "resolution-mode": string; }[]' has no properties in common with type 'ImportCallOptions'. +/other3.ts(4,56): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. +/other3.ts(6,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other3.ts(6,48): error TS1005: '{' expected. +/other3.ts(6,50): error TS2538: Type '{ "resolution-mode": "require"; }' cannot be used as an index type. +/other3.ts(6,100): error TS1005: ',' expected. +/other3.ts(7,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other3.ts(7,48): error TS1005: '{' expected. +/other3.ts(7,50): error TS2538: Type '{ "resolution-mode": "import"; }' cannot be used as an index type. +/other3.ts(7,98): error TS1005: ',' expected. +/other4.ts(6,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other4.ts(6,21): error TS1005: '{' expected. +/other4.ts(6,21): error TS2448: Block-scoped variable 'Asserts1' used before its declaration. +/other4.ts(6,29): error TS1128: Declaration or statement expected. +/other4.ts(6,30): error TS1128: Declaration or statement expected. +/other4.ts(6,31): error TS2448: Block-scoped variable 'RequireInterface' used before its declaration. +/other4.ts(7,21): error TS2448: Block-scoped variable 'Asserts2' used before its declaration. +/other4.ts(7,31): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. +/other4.ts(9,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other4.ts(9,48): error TS1005: '{' expected. +/other4.ts(9,56): error TS1005: ',' expected. +/other4.ts(9,57): error TS1134: Variable declaration expected. +/other4.ts(9,74): error TS1005: ',' expected. +/other4.ts(10,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other4.ts(10,48): error TS1005: '{' expected. +/other4.ts(10,56): error TS1005: ',' expected. +/other4.ts(10,57): error TS1134: Variable declaration expected. +/other4.ts(10,73): error TS1005: ',' expected. +/other5.ts(2,31): error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. +/other5.ts(3,31): error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. +/other5.ts(3,37): error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. +/other5.ts(5,58): error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. +/other5.ts(6,58): error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. +/other5.ts(6,64): error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. + + +==== /node_modules/pkg/package.json (0 errors) ==== + { + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } + } +==== /node_modules/pkg/import.d.ts (0 errors) ==== + export interface ImportInterface {} +==== /node_modules/pkg/require.d.ts (0 errors) ==== + export interface RequireInterface {} +==== /index.ts (2 errors) ==== + export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface + ~~~~~~~~ +!!! error TS1453: `resolution-mode` should be either `require` or `import`. + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + + export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); + ~~~~~~~~ +!!! error TS1453: `resolution-mode` should be either `require` or `import`. + export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +==== /other.ts (27 errors) ==== + // missing assert: + export type LocalInterface = + & import("pkg", {"resolution-mode": "require"}).RequireInterface + ~~~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~~~~~~~~~~ +!!! error TS1005: 'assert' expected. +!!! related TS1007 /other.ts:3:21: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'RequireInterface'. + & import("pkg", {"resolution-mode": "import"}).ImportInterface; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ "resolution-mode": string; }' is not assignable to type 'ImportCallOptions'. +!!! error TS2322: Object literal may only specify known properties, and '"resolution-mode"' does not exist in type 'ImportCallOptions'. + ~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. + + export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); + ~~~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~~~~~~~~~~ +!!! error TS1005: 'assert' expected. +!!! related TS1007 /other.ts:6:48: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'RequireInterface'. + ~ +!!! error TS1128: Declaration or statement expected. + export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); + ~~~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~~~~~~~~~~ +!!! error TS1005: 'assert' expected. +!!! related TS1007 /other.ts:7:48: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'ImportInterface'. + ~ +!!! error TS1128: Declaration or statement expected. +==== /other2.ts (6 errors) ==== + // wrong assertion key + export type LocalInterface = + & import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface + ~~~~~~~~~~~~~~~~~ +!!! error TS1455: `resolution-mode` is the only valid key for type import assertions. + & import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface; + ~~~~~~~~~~~~~~~~~ +!!! error TS1455: `resolution-mode` is the only valid key for type import assertions. + ~~~~~~~~~~~~~~~ +!!! error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. + + export const a = (null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface); + ~~~~~~~~~~~~~~~~~ +!!! error TS1455: `resolution-mode` is the only valid key for type import assertions. + export const b = (null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface); + ~~~~~~~~~~~~~~~~~ +!!! error TS1455: `resolution-mode` is the only valid key for type import assertions. + ~~~~~~~~~~~~~~~ +!!! error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. +==== /other3.ts (16 errors) ==== + // Array instead of object-y thing + export type LocalInterface = + & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other3.ts:3:21: The parser expected to find a '}' to match the '{' token here. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type '{ "resolution-mode": "require"; }' cannot be used as an index type. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'RequireInterface'. + & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2559: Type '{ "resolution-mode": string; }[]' has no properties in common with type 'ImportCallOptions'. + ~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. + + export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other3.ts:6:48: The parser expected to find a '}' to match the '{' token here. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type '{ "resolution-mode": "require"; }' cannot be used as an index type. + ~ +!!! error TS1005: ',' expected. + export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other3.ts:7:48: The parser expected to find a '}' to match the '{' token here. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type '{ "resolution-mode": "import"; }' cannot be used as an index type. + ~ +!!! error TS1005: ',' expected. +==== /other4.ts (18 errors) ==== + // Indirected assertion objecty-thing - not allowed + type Asserts1 = { assert: {"resolution-mode": "require"} }; + type Asserts2 = { assert: {"resolution-mode": "import"} }; + + export type LocalInterface = + & import("pkg", Asserts1).RequireInterface + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other4.ts:6:21: The parser expected to find a '}' to match the '{' token here. + ~~~~~~~~ +!!! error TS2448: Block-scoped variable 'Asserts1' used before its declaration. +!!! related TS2728 /other4.ts:9:48: 'Asserts1' is declared here. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~ +!!! error TS2448: Block-scoped variable 'RequireInterface' used before its declaration. +!!! related TS2728 /other4.ts:9:58: 'RequireInterface' is declared here. + & import("pkg", Asserts2).ImportInterface; + ~~~~~~~~ +!!! error TS2448: Block-scoped variable 'Asserts2' used before its declaration. +!!! related TS2728 /other4.ts:10:48: 'Asserts2' is declared here. + ~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. + + export const a = (null as any as import("pkg", Asserts1).RequireInterface); + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other4.ts:9:48: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1134: Variable declaration expected. + ~ +!!! error TS1005: ',' expected. + export const b = (null as any as import("pkg", Asserts2).ImportInterface); + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other4.ts:10:48: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1134: Variable declaration expected. + ~ +!!! error TS1005: ',' expected. +==== /other5.ts (6 errors) ==== + export type LocalInterface = + & import("pkg", { assert: {} }).RequireInterface + ~~ +!!! error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. + & import("pkg", { assert: {} }).ImportInterface; + ~~ +!!! error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. + ~~~~~~~~~~~~~~~ +!!! error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. + + export const a = (null as any as import("pkg", { assert: {} }).RequireInterface); + ~~ +!!! error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. + export const b = (null as any as import("pkg", { assert: {} }).ImportInterface); + ~~ +!!! error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. + ~~~~~~~~~~~~~~~ +!!! error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. + \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).js b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).js new file mode 100644 index 0000000000000..2af308575c13c --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).js @@ -0,0 +1,147 @@ +//// [tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmitErrors1.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [index.ts] +export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +//// [other.ts] +// missing assert: +export type LocalInterface = + & import("pkg", {"resolution-mode": "require"}).RequireInterface + & import("pkg", {"resolution-mode": "import"}).ImportInterface; + +export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); +export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); +//// [other2.ts] +// wrong assertion key +export type LocalInterface = + & import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface); +//// [other3.ts] +// Array instead of object-y thing +export type LocalInterface = + & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface + & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; + +export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); +export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); +//// [other4.ts] +// Indirected assertion objecty-thing - not allowed +type Asserts1 = { assert: {"resolution-mode": "require"} }; +type Asserts2 = { assert: {"resolution-mode": "import"} }; + +export type LocalInterface = + & import("pkg", Asserts1).RequireInterface + & import("pkg", Asserts2).ImportInterface; + +export const a = (null as any as import("pkg", Asserts1).RequireInterface); +export const b = (null as any as import("pkg", Asserts2).ImportInterface); +//// [other5.ts] +export type LocalInterface = + & import("pkg", { assert: {} }).RequireInterface + & import("pkg", { assert: {} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {} }).ImportInterface); + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = null; +exports.b = null; +//// [other.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +"resolution-mode"; +"require"; +RequireInterface + & import("pkg", { "resolution-mode": "import" }).ImportInterface; +exports.a = null; +"resolution-mode"; +"require"; +RequireInterface; +; +exports.b = null; +"resolution-mode"; +"import"; +ImportInterface; +; +//// [other2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = null; +exports.b = null; +//// [other3.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +RequireInterface + & import("pkg", [{ "resolution-mode": "import" }]).ImportInterface; +exports.a = null.RequireInterface; +exports.b = null.ImportInterface; +//// [other4.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ImportInterface = exports.Asserts2 = exports.b = exports.RequireInterface = exports.Asserts1 = exports.a = void 0; +exports.Asserts1; +exports.RequireInterface + & import("pkg", exports.Asserts2).ImportInterface; +exports.a = null; +exports.b = null; +//// [other5.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = null; +exports.b = null; + + +//// [index.d.ts] +export declare type LocalInterface = import("pkg", { assert: { "resolution-mode": "foobar" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; +export declare const a: import("pkg").RequireInterface; +export declare const b: import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; +//// [other.d.ts] +export declare type LocalInterface = import("pkg", { assert: {} }); +export declare const a: any; +export declare const b: any; +//// [other2.d.ts] +export declare type LocalInterface = import("pkg", { assert: { "resolution-m0de": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-m0de": "import" } }).ImportInterface; +export declare const a: import("pkg").RequireInterface; +export declare const b: any; +//// [other3.d.ts] +export declare type LocalInterface = import("pkg", { assert: {} })[{ + "resolution-mode": "require"; +}]; +export declare const a: any; +export declare const b: any; +//// [other4.d.ts] +export declare type LocalInterface = import("pkg", { assert: {} }); +export declare const a: any, Asserts1: any, RequireInterface: any; +export declare const b: any, Asserts2: any, ImportInterface: any; +//// [other5.d.ts] +export declare type LocalInterface = import("pkg", { assert: {} }).RequireInterface & import("pkg", { assert: {} }).ImportInterface; +export declare const a: import("pkg").RequireInterface; +export declare const b: any; diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).symbols b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).symbols new file mode 100644 index 0000000000000..79f21dd040c3a --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).symbols @@ -0,0 +1,128 @@ +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +=== /index.ts === +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); +>a : Symbol(a, Decl(index.ts, 4, 12)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +>b : Symbol(b, Decl(index.ts, 5, 12)) +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /other.ts === +// missing assert: +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other.ts, 0, 0)) + + & import("pkg", {"resolution-mode": "require"}).RequireInterface + & import("pkg", {"resolution-mode": "import"}).ImportInterface; +>"pkg" : Symbol("/node_modules/pkg/import", Decl(import.d.ts, 0, 0)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other.ts, 3, 21)) + +export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); +>a : Symbol(a, Decl(other.ts, 5, 12)) + +export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); +>b : Symbol(b, Decl(other.ts, 6, 12)) + +=== /other2.ts === +// wrong assertion key +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other2.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface); +>a : Symbol(a, Decl(other2.ts, 5, 12)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +export const b = (null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface); +>b : Symbol(b, Decl(other2.ts, 6, 12)) + +=== /other3.ts === +// Array instead of object-y thing +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other3.ts, 0, 0)) + + & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface +>"resolution-mode" : Symbol("resolution-mode", Decl(other3.ts, 2, 23)) + + & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; +>"pkg" : Symbol("/node_modules/pkg/import", Decl(import.d.ts, 0, 0)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other3.ts, 3, 23)) + +export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); +>a : Symbol(a, Decl(other3.ts, 5, 12)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other3.ts, 5, 50)) + +export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); +>b : Symbol(b, Decl(other3.ts, 6, 12)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other3.ts, 6, 50)) + +=== /other4.ts === +// Indirected assertion objecty-thing - not allowed +type Asserts1 = { assert: {"resolution-mode": "require"} }; +>Asserts1 : Symbol(Asserts1, Decl(other4.ts, 0, 0), Decl(other4.ts, 8, 46)) +>assert : Symbol(assert, Decl(other4.ts, 1, 17)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other4.ts, 1, 27)) + +type Asserts2 = { assert: {"resolution-mode": "import"} }; +>Asserts2 : Symbol(Asserts2, Decl(other4.ts, 1, 59), Decl(other4.ts, 9, 46)) +>assert : Symbol(assert, Decl(other4.ts, 2, 17)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other4.ts, 2, 27)) + +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other4.ts, 2, 58)) + + & import("pkg", Asserts1).RequireInterface +>Asserts1 : Symbol(Asserts1, Decl(other4.ts, 8, 46)) +>RequireInterface : Symbol(RequireInterface, Decl(other4.ts, 8, 57)) + + & import("pkg", Asserts2).ImportInterface; +>"pkg" : Symbol("/node_modules/pkg/import", Decl(import.d.ts, 0, 0)) +>Asserts2 : Symbol(Asserts2, Decl(other4.ts, 9, 46)) + +export const a = (null as any as import("pkg", Asserts1).RequireInterface); +>a : Symbol(a, Decl(other4.ts, 8, 12)) +>Asserts1 : Symbol(Asserts1, Decl(other4.ts, 8, 46)) +>RequireInterface : Symbol(RequireInterface, Decl(other4.ts, 8, 57)) + +export const b = (null as any as import("pkg", Asserts2).ImportInterface); +>b : Symbol(b, Decl(other4.ts, 9, 12)) +>Asserts2 : Symbol(Asserts2, Decl(other4.ts, 9, 46)) +>ImportInterface : Symbol(ImportInterface, Decl(other4.ts, 9, 57)) + +=== /other5.ts === +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other5.ts, 0, 0)) + + & import("pkg", { assert: {} }).RequireInterface +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + + & import("pkg", { assert: {} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {} }).RequireInterface); +>a : Symbol(a, Decl(other5.ts, 4, 12)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +export const b = (null as any as import("pkg", { assert: {} }).ImportInterface); +>b : Symbol(b, Decl(other5.ts, 5, 12)) + diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).types b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).types new file mode 100644 index 0000000000000..148bff242c6ba --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).types @@ -0,0 +1,193 @@ +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +No type information for this code.=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code.=== /index.ts === +export type LocalInterface = +>LocalInterface : LocalInterface + + & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); +>a : import("/node_modules/pkg/require").RequireInterface +>(null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface) : import("/node_modules/pkg/require").RequireInterface +>null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface : import("/node_modules/pkg/require").RequireInterface +>null as any : any +>null : null + +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +>b : import("/node_modules/pkg/import").ImportInterface +>(null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface) : import("/node_modules/pkg/import").ImportInterface +>null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface : import("/node_modules/pkg/import").ImportInterface +>null as any : any +>null : null + +=== /other.ts === +// missing assert: +export type LocalInterface = +>LocalInterface : any + + & import("pkg", {"resolution-mode": "require"}).RequireInterface +>"resolution-mode" : "resolution-mode" +>"require" : "require" +>RequireInterface & import("pkg", {"resolution-mode": "import"}).ImportInterface : number +>RequireInterface : any + + & import("pkg", {"resolution-mode": "import"}).ImportInterface; +>import("pkg", {"resolution-mode": "import"}).ImportInterface : any +>import("pkg", {"resolution-mode": "import"}) : Promise<{ default: typeof import("/node_modules/pkg/import"); }> +>"pkg" : "pkg" +>{"resolution-mode": "import"} : { "resolution-mode": string; } +>"resolution-mode" : string +>"import" : "import" +>ImportInterface : any + +export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); +>a : any +>(null as any as import("pkg", { : any +>null as any as import("pkg", { : any +>null as any : any +>null : null +>"resolution-mode" : "resolution-mode" +>"require" : "require" +>RequireInterface : any + +export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); +>b : any +>(null as any as import("pkg", { : any +>null as any as import("pkg", { : any +>null as any : any +>null : null +>"resolution-mode" : "resolution-mode" +>"import" : "import" +>ImportInterface : any + +=== /other2.ts === +// wrong assertion key +export type LocalInterface = +>LocalInterface : any + + & import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface); +>a : import("/node_modules/pkg/require").RequireInterface +>(null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface) : import("/node_modules/pkg/require").RequireInterface +>null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface : import("/node_modules/pkg/require").RequireInterface +>null as any : any +>null : null + +export const b = (null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface); +>b : any +>(null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface) : any +>null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface : any +>null as any : any +>null : null + +=== /other3.ts === +// Array instead of object-y thing +export type LocalInterface = +>LocalInterface : any + + & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface +>"resolution-mode" : "require" +>RequireInterface & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface : number +>RequireInterface : any + + & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; +>import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface : any +>import("pkg", [ {"resolution-mode": "import"} ]) : Promise<{ default: typeof import("/node_modules/pkg/import"); }> +>"pkg" : "pkg" +>[ {"resolution-mode": "import"} ] : { "resolution-mode": string; }[] +>{"resolution-mode": "import"} : { "resolution-mode": string; } +>"resolution-mode" : string +>"import" : "import" +>ImportInterface : any + +export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); +>a : any +>(null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface : any +>(null as any as import("pkg", [ {"resolution-mode": "require"} ]) : any +>null as any as import("pkg", [ {"resolution-mode": "require"} ] : any +>null as any : any +>null : null +>"resolution-mode" : "require" +>RequireInterface : any + +export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); +>b : any +>(null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface : any +>(null as any as import("pkg", [ {"resolution-mode": "import"} ]) : any +>null as any as import("pkg", [ {"resolution-mode": "import"} ] : any +>null as any : any +>null : null +>"resolution-mode" : "import" +>ImportInterface : any + +=== /other4.ts === +// Indirected assertion objecty-thing - not allowed +type Asserts1 = { assert: {"resolution-mode": "require"} }; +>Asserts1 : Asserts1 +>assert : { "resolution-mode": "require"; } +>"resolution-mode" : "require" + +type Asserts2 = { assert: {"resolution-mode": "import"} }; +>Asserts2 : Asserts2 +>assert : { "resolution-mode": "import"; } +>"resolution-mode" : "import" + +export type LocalInterface = +>LocalInterface : any + + & import("pkg", Asserts1).RequireInterface +>Asserts1 : any +>RequireInterface & import("pkg", Asserts2).ImportInterface : number +>RequireInterface : any + + & import("pkg", Asserts2).ImportInterface; +>import("pkg", Asserts2).ImportInterface : any +>import("pkg", Asserts2) : Promise<{ default: typeof import("/node_modules/pkg/import"); }> +>"pkg" : "pkg" +>Asserts2 : any +>ImportInterface : any + +export const a = (null as any as import("pkg", Asserts1).RequireInterface); +>a : any +>(null as any as import("pkg", : any +>null as any as import("pkg", : any +>null as any : any +>null : null +>Asserts1 : any +>RequireInterface : any + +export const b = (null as any as import("pkg", Asserts2).ImportInterface); +>b : any +>(null as any as import("pkg", : any +>null as any as import("pkg", : any +>null as any : any +>null : null +>Asserts2 : any +>ImportInterface : any + +=== /other5.ts === +export type LocalInterface = +>LocalInterface : any + + & import("pkg", { assert: {} }).RequireInterface + & import("pkg", { assert: {} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {} }).RequireInterface); +>a : import("/node_modules/pkg/require").RequireInterface +>(null as any as import("pkg", { assert: {} }).RequireInterface) : import("/node_modules/pkg/require").RequireInterface +>null as any as import("pkg", { assert: {} }).RequireInterface : import("/node_modules/pkg/require").RequireInterface +>null as any : any +>null : null + +export const b = (null as any as import("pkg", { assert: {} }).ImportInterface); +>b : any +>(null as any as import("pkg", { assert: {} }).ImportInterface) : any +>null as any as import("pkg", { assert: {} }).ImportInterface : any +>null as any : any +>null : null + diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).errors.txt new file mode 100644 index 0000000000000..1159c2b965e3f --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).errors.txt @@ -0,0 +1,304 @@ +/index.ts(2,51): error TS1453: `resolution-mode` should be either `require` or `import`. +/index.ts(5,78): error TS1453: `resolution-mode` should be either `require` or `import`. +/other.ts(3,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other.ts(3,22): error TS1005: 'assert' expected. +/other.ts(3,39): error TS1005: ';' expected. +/other.ts(3,50): error TS1128: Declaration or statement expected. +/other.ts(3,51): error TS1128: Declaration or statement expected. +/other.ts(3,52): error TS1128: Declaration or statement expected. +/other.ts(3,53): error TS2304: Cannot find name 'RequireInterface'. +/other.ts(4,22): error TS2322: Type '{ "resolution-mode": string; }' is not assignable to type 'ImportCallOptions'. + Object literal may only specify known properties, and '"resolution-mode"' does not exist in type 'ImportCallOptions'. +/other.ts(4,52): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. +/other.ts(6,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other.ts(6,49): error TS1005: 'assert' expected. +/other.ts(6,66): error TS1005: ';' expected. +/other.ts(6,77): error TS1128: Declaration or statement expected. +/other.ts(6,78): error TS1128: Declaration or statement expected. +/other.ts(6,79): error TS1128: Declaration or statement expected. +/other.ts(6,80): error TS1434: Unexpected keyword or identifier. +/other.ts(6,80): error TS2304: Cannot find name 'RequireInterface'. +/other.ts(6,96): error TS1128: Declaration or statement expected. +/other.ts(7,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other.ts(7,49): error TS1005: 'assert' expected. +/other.ts(7,66): error TS1005: ';' expected. +/other.ts(7,76): error TS1128: Declaration or statement expected. +/other.ts(7,77): error TS1128: Declaration or statement expected. +/other.ts(7,78): error TS1128: Declaration or statement expected. +/other.ts(7,79): error TS1434: Unexpected keyword or identifier. +/other.ts(7,79): error TS2304: Cannot find name 'ImportInterface'. +/other.ts(7,94): error TS1128: Declaration or statement expected. +/other2.ts(3,32): error TS1455: `resolution-mode` is the only valid key for type import assertions. +/other2.ts(4,32): error TS1455: `resolution-mode` is the only valid key for type import assertions. +/other2.ts(4,64): error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. +/other2.ts(6,59): error TS1455: `resolution-mode` is the only valid key for type import assertions. +/other2.ts(7,59): error TS1455: `resolution-mode` is the only valid key for type import assertions. +/other2.ts(7,91): error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. +/other3.ts(3,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other3.ts(3,21): error TS1005: '{' expected. +/other3.ts(3,23): error TS2538: Type '{ "resolution-mode": "require"; }' cannot be used as an index type. +/other3.ts(3,55): error TS1005: ';' expected. +/other3.ts(3,56): error TS1128: Declaration or statement expected. +/other3.ts(3,57): error TS2304: Cannot find name 'RequireInterface'. +/other3.ts(4,21): error TS2559: Type '{ "resolution-mode": string; }[]' has no properties in common with type 'ImportCallOptions'. +/other3.ts(4,56): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. +/other3.ts(6,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other3.ts(6,48): error TS1005: '{' expected. +/other3.ts(6,50): error TS2538: Type '{ "resolution-mode": "require"; }' cannot be used as an index type. +/other3.ts(6,100): error TS1005: ',' expected. +/other3.ts(7,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other3.ts(7,48): error TS1005: '{' expected. +/other3.ts(7,50): error TS2538: Type '{ "resolution-mode": "import"; }' cannot be used as an index type. +/other3.ts(7,98): error TS1005: ',' expected. +/other4.ts(6,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other4.ts(6,21): error TS1005: '{' expected. +/other4.ts(6,21): error TS2448: Block-scoped variable 'Asserts1' used before its declaration. +/other4.ts(6,29): error TS1128: Declaration or statement expected. +/other4.ts(6,30): error TS1128: Declaration or statement expected. +/other4.ts(6,31): error TS2448: Block-scoped variable 'RequireInterface' used before its declaration. +/other4.ts(7,21): error TS2448: Block-scoped variable 'Asserts2' used before its declaration. +/other4.ts(7,31): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. +/other4.ts(9,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other4.ts(9,48): error TS1005: '{' expected. +/other4.ts(9,56): error TS1005: ',' expected. +/other4.ts(9,57): error TS1134: Variable declaration expected. +/other4.ts(9,74): error TS1005: ',' expected. +/other4.ts(10,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? +/other4.ts(10,48): error TS1005: '{' expected. +/other4.ts(10,56): error TS1005: ',' expected. +/other4.ts(10,57): error TS1134: Variable declaration expected. +/other4.ts(10,73): error TS1005: ',' expected. +/other5.ts(2,31): error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. +/other5.ts(3,31): error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. +/other5.ts(3,37): error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. +/other5.ts(5,58): error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. +/other5.ts(6,58): error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. +/other5.ts(6,64): error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. + + +==== /node_modules/pkg/package.json (0 errors) ==== + { + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } + } +==== /node_modules/pkg/import.d.ts (0 errors) ==== + export interface ImportInterface {} +==== /node_modules/pkg/require.d.ts (0 errors) ==== + export interface RequireInterface {} +==== /index.ts (2 errors) ==== + export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface + ~~~~~~~~ +!!! error TS1453: `resolution-mode` should be either `require` or `import`. + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + + export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); + ~~~~~~~~ +!!! error TS1453: `resolution-mode` should be either `require` or `import`. + export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +==== /other.ts (27 errors) ==== + // missing assert: + export type LocalInterface = + & import("pkg", {"resolution-mode": "require"}).RequireInterface + ~~~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~~~~~~~~~~ +!!! error TS1005: 'assert' expected. +!!! related TS1007 /other.ts:3:21: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'RequireInterface'. + & import("pkg", {"resolution-mode": "import"}).ImportInterface; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ "resolution-mode": string; }' is not assignable to type 'ImportCallOptions'. +!!! error TS2322: Object literal may only specify known properties, and '"resolution-mode"' does not exist in type 'ImportCallOptions'. + ~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. + + export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); + ~~~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~~~~~~~~~~ +!!! error TS1005: 'assert' expected. +!!! related TS1007 /other.ts:6:48: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'RequireInterface'. + ~ +!!! error TS1128: Declaration or statement expected. + export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); + ~~~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~~~~~~~~~~ +!!! error TS1005: 'assert' expected. +!!! related TS1007 /other.ts:7:48: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'ImportInterface'. + ~ +!!! error TS1128: Declaration or statement expected. +==== /other2.ts (6 errors) ==== + // wrong assertion key + export type LocalInterface = + & import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface + ~~~~~~~~~~~~~~~~~ +!!! error TS1455: `resolution-mode` is the only valid key for type import assertions. + & import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface; + ~~~~~~~~~~~~~~~~~ +!!! error TS1455: `resolution-mode` is the only valid key for type import assertions. + ~~~~~~~~~~~~~~~ +!!! error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. + + export const a = (null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface); + ~~~~~~~~~~~~~~~~~ +!!! error TS1455: `resolution-mode` is the only valid key for type import assertions. + export const b = (null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface); + ~~~~~~~~~~~~~~~~~ +!!! error TS1455: `resolution-mode` is the only valid key for type import assertions. + ~~~~~~~~~~~~~~~ +!!! error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. +==== /other3.ts (16 errors) ==== + // Array instead of object-y thing + export type LocalInterface = + & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other3.ts:3:21: The parser expected to find a '}' to match the '{' token here. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type '{ "resolution-mode": "require"; }' cannot be used as an index type. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'RequireInterface'. + & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2559: Type '{ "resolution-mode": string; }[]' has no properties in common with type 'ImportCallOptions'. + ~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. + + export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other3.ts:6:48: The parser expected to find a '}' to match the '{' token here. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type '{ "resolution-mode": "require"; }' cannot be used as an index type. + ~ +!!! error TS1005: ',' expected. + export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other3.ts:7:48: The parser expected to find a '}' to match the '{' token here. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type '{ "resolution-mode": "import"; }' cannot be used as an index type. + ~ +!!! error TS1005: ',' expected. +==== /other4.ts (18 errors) ==== + // Indirected assertion objecty-thing - not allowed + type Asserts1 = { assert: {"resolution-mode": "require"} }; + type Asserts2 = { assert: {"resolution-mode": "import"} }; + + export type LocalInterface = + & import("pkg", Asserts1).RequireInterface + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other4.ts:6:21: The parser expected to find a '}' to match the '{' token here. + ~~~~~~~~ +!!! error TS2448: Block-scoped variable 'Asserts1' used before its declaration. +!!! related TS2728 /other4.ts:9:48: 'Asserts1' is declared here. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~ +!!! error TS2448: Block-scoped variable 'RequireInterface' used before its declaration. +!!! related TS2728 /other4.ts:9:58: 'RequireInterface' is declared here. + & import("pkg", Asserts2).ImportInterface; + ~~~~~~~~ +!!! error TS2448: Block-scoped variable 'Asserts2' used before its declaration. +!!! related TS2728 /other4.ts:10:48: 'Asserts2' is declared here. + ~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'. + + export const a = (null as any as import("pkg", Asserts1).RequireInterface); + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other4.ts:9:48: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1134: Variable declaration expected. + ~ +!!! error TS1005: ',' expected. + export const b = (null as any as import("pkg", Asserts2).ImportInterface); + ~~~~~~~~~~~~~ +!!! error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? + ~~~~~~~~ +!!! error TS1005: '{' expected. +!!! related TS1007 /other4.ts:10:48: The parser expected to find a '}' to match the '{' token here. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1134: Variable declaration expected. + ~ +!!! error TS1005: ',' expected. +==== /other5.ts (6 errors) ==== + export type LocalInterface = + & import("pkg", { assert: {} }).RequireInterface + ~~ +!!! error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. + & import("pkg", { assert: {} }).ImportInterface; + ~~ +!!! error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. + ~~~~~~~~~~~~~~~ +!!! error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. + + export const a = (null as any as import("pkg", { assert: {} }).RequireInterface); + ~~ +!!! error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. + export const b = (null as any as import("pkg", { assert: {} }).ImportInterface); + ~~ +!!! error TS1456: Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`. + ~~~~~~~~~~~~~~~ +!!! error TS2694: Namespace '"/node_modules/pkg/require"' has no exported member 'ImportInterface'. + \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).js b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).js new file mode 100644 index 0000000000000..2af308575c13c --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).js @@ -0,0 +1,147 @@ +//// [tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmitErrors1.ts] //// + +//// [package.json] +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +//// [import.d.ts] +export interface ImportInterface {} +//// [require.d.ts] +export interface RequireInterface {} +//// [index.ts] +export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +//// [other.ts] +// missing assert: +export type LocalInterface = + & import("pkg", {"resolution-mode": "require"}).RequireInterface + & import("pkg", {"resolution-mode": "import"}).ImportInterface; + +export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); +export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); +//// [other2.ts] +// wrong assertion key +export type LocalInterface = + & import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface); +//// [other3.ts] +// Array instead of object-y thing +export type LocalInterface = + & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface + & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; + +export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); +export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); +//// [other4.ts] +// Indirected assertion objecty-thing - not allowed +type Asserts1 = { assert: {"resolution-mode": "require"} }; +type Asserts2 = { assert: {"resolution-mode": "import"} }; + +export type LocalInterface = + & import("pkg", Asserts1).RequireInterface + & import("pkg", Asserts2).ImportInterface; + +export const a = (null as any as import("pkg", Asserts1).RequireInterface); +export const b = (null as any as import("pkg", Asserts2).ImportInterface); +//// [other5.ts] +export type LocalInterface = + & import("pkg", { assert: {} }).RequireInterface + & import("pkg", { assert: {} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {} }).ImportInterface); + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = null; +exports.b = null; +//// [other.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +"resolution-mode"; +"require"; +RequireInterface + & import("pkg", { "resolution-mode": "import" }).ImportInterface; +exports.a = null; +"resolution-mode"; +"require"; +RequireInterface; +; +exports.b = null; +"resolution-mode"; +"import"; +ImportInterface; +; +//// [other2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = null; +exports.b = null; +//// [other3.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +RequireInterface + & import("pkg", [{ "resolution-mode": "import" }]).ImportInterface; +exports.a = null.RequireInterface; +exports.b = null.ImportInterface; +//// [other4.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ImportInterface = exports.Asserts2 = exports.b = exports.RequireInterface = exports.Asserts1 = exports.a = void 0; +exports.Asserts1; +exports.RequireInterface + & import("pkg", exports.Asserts2).ImportInterface; +exports.a = null; +exports.b = null; +//// [other5.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = null; +exports.b = null; + + +//// [index.d.ts] +export declare type LocalInterface = import("pkg", { assert: { "resolution-mode": "foobar" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; +export declare const a: import("pkg").RequireInterface; +export declare const b: import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; +//// [other.d.ts] +export declare type LocalInterface = import("pkg", { assert: {} }); +export declare const a: any; +export declare const b: any; +//// [other2.d.ts] +export declare type LocalInterface = import("pkg", { assert: { "resolution-m0de": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-m0de": "import" } }).ImportInterface; +export declare const a: import("pkg").RequireInterface; +export declare const b: any; +//// [other3.d.ts] +export declare type LocalInterface = import("pkg", { assert: {} })[{ + "resolution-mode": "require"; +}]; +export declare const a: any; +export declare const b: any; +//// [other4.d.ts] +export declare type LocalInterface = import("pkg", { assert: {} }); +export declare const a: any, Asserts1: any, RequireInterface: any; +export declare const b: any, Asserts2: any, ImportInterface: any; +//// [other5.d.ts] +export declare type LocalInterface = import("pkg", { assert: {} }).RequireInterface & import("pkg", { assert: {} }).ImportInterface; +export declare const a: import("pkg").RequireInterface; +export declare const b: any; diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).symbols b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).symbols new file mode 100644 index 0000000000000..79f21dd040c3a --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).symbols @@ -0,0 +1,128 @@ +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +=== /index.ts === +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); +>a : Symbol(a, Decl(index.ts, 4, 12)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +>b : Symbol(b, Decl(index.ts, 5, 12)) +>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0)) + +=== /other.ts === +// missing assert: +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other.ts, 0, 0)) + + & import("pkg", {"resolution-mode": "require"}).RequireInterface + & import("pkg", {"resolution-mode": "import"}).ImportInterface; +>"pkg" : Symbol("/node_modules/pkg/import", Decl(import.d.ts, 0, 0)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other.ts, 3, 21)) + +export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); +>a : Symbol(a, Decl(other.ts, 5, 12)) + +export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); +>b : Symbol(b, Decl(other.ts, 6, 12)) + +=== /other2.ts === +// wrong assertion key +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other2.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + + & import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface); +>a : Symbol(a, Decl(other2.ts, 5, 12)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +export const b = (null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface); +>b : Symbol(b, Decl(other2.ts, 6, 12)) + +=== /other3.ts === +// Array instead of object-y thing +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other3.ts, 0, 0)) + + & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface +>"resolution-mode" : Symbol("resolution-mode", Decl(other3.ts, 2, 23)) + + & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; +>"pkg" : Symbol("/node_modules/pkg/import", Decl(import.d.ts, 0, 0)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other3.ts, 3, 23)) + +export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); +>a : Symbol(a, Decl(other3.ts, 5, 12)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other3.ts, 5, 50)) + +export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); +>b : Symbol(b, Decl(other3.ts, 6, 12)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other3.ts, 6, 50)) + +=== /other4.ts === +// Indirected assertion objecty-thing - not allowed +type Asserts1 = { assert: {"resolution-mode": "require"} }; +>Asserts1 : Symbol(Asserts1, Decl(other4.ts, 0, 0), Decl(other4.ts, 8, 46)) +>assert : Symbol(assert, Decl(other4.ts, 1, 17)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other4.ts, 1, 27)) + +type Asserts2 = { assert: {"resolution-mode": "import"} }; +>Asserts2 : Symbol(Asserts2, Decl(other4.ts, 1, 59), Decl(other4.ts, 9, 46)) +>assert : Symbol(assert, Decl(other4.ts, 2, 17)) +>"resolution-mode" : Symbol("resolution-mode", Decl(other4.ts, 2, 27)) + +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other4.ts, 2, 58)) + + & import("pkg", Asserts1).RequireInterface +>Asserts1 : Symbol(Asserts1, Decl(other4.ts, 8, 46)) +>RequireInterface : Symbol(RequireInterface, Decl(other4.ts, 8, 57)) + + & import("pkg", Asserts2).ImportInterface; +>"pkg" : Symbol("/node_modules/pkg/import", Decl(import.d.ts, 0, 0)) +>Asserts2 : Symbol(Asserts2, Decl(other4.ts, 9, 46)) + +export const a = (null as any as import("pkg", Asserts1).RequireInterface); +>a : Symbol(a, Decl(other4.ts, 8, 12)) +>Asserts1 : Symbol(Asserts1, Decl(other4.ts, 8, 46)) +>RequireInterface : Symbol(RequireInterface, Decl(other4.ts, 8, 57)) + +export const b = (null as any as import("pkg", Asserts2).ImportInterface); +>b : Symbol(b, Decl(other4.ts, 9, 12)) +>Asserts2 : Symbol(Asserts2, Decl(other4.ts, 9, 46)) +>ImportInterface : Symbol(ImportInterface, Decl(other4.ts, 9, 57)) + +=== /other5.ts === +export type LocalInterface = +>LocalInterface : Symbol(LocalInterface, Decl(other5.ts, 0, 0)) + + & import("pkg", { assert: {} }).RequireInterface +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + + & import("pkg", { assert: {} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {} }).RequireInterface); +>a : Symbol(a, Decl(other5.ts, 4, 12)) +>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0)) + +export const b = (null as any as import("pkg", { assert: {} }).ImportInterface); +>b : Symbol(b, Decl(other5.ts, 5, 12)) + diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).types b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).types new file mode 100644 index 0000000000000..148bff242c6ba --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).types @@ -0,0 +1,193 @@ +=== /node_modules/pkg/import.d.ts === +export interface ImportInterface {} +No type information for this code.=== /node_modules/pkg/require.d.ts === +export interface RequireInterface {} +No type information for this code.=== /index.ts === +export type LocalInterface = +>LocalInterface : LocalInterface + + & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); +>a : import("/node_modules/pkg/require").RequireInterface +>(null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface) : import("/node_modules/pkg/require").RequireInterface +>null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface : import("/node_modules/pkg/require").RequireInterface +>null as any : any +>null : null + +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +>b : import("/node_modules/pkg/import").ImportInterface +>(null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface) : import("/node_modules/pkg/import").ImportInterface +>null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface : import("/node_modules/pkg/import").ImportInterface +>null as any : any +>null : null + +=== /other.ts === +// missing assert: +export type LocalInterface = +>LocalInterface : any + + & import("pkg", {"resolution-mode": "require"}).RequireInterface +>"resolution-mode" : "resolution-mode" +>"require" : "require" +>RequireInterface & import("pkg", {"resolution-mode": "import"}).ImportInterface : number +>RequireInterface : any + + & import("pkg", {"resolution-mode": "import"}).ImportInterface; +>import("pkg", {"resolution-mode": "import"}).ImportInterface : any +>import("pkg", {"resolution-mode": "import"}) : Promise<{ default: typeof import("/node_modules/pkg/import"); }> +>"pkg" : "pkg" +>{"resolution-mode": "import"} : { "resolution-mode": string; } +>"resolution-mode" : string +>"import" : "import" +>ImportInterface : any + +export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); +>a : any +>(null as any as import("pkg", { : any +>null as any as import("pkg", { : any +>null as any : any +>null : null +>"resolution-mode" : "resolution-mode" +>"require" : "require" +>RequireInterface : any + +export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); +>b : any +>(null as any as import("pkg", { : any +>null as any as import("pkg", { : any +>null as any : any +>null : null +>"resolution-mode" : "resolution-mode" +>"import" : "import" +>ImportInterface : any + +=== /other2.ts === +// wrong assertion key +export type LocalInterface = +>LocalInterface : any + + & import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface); +>a : import("/node_modules/pkg/require").RequireInterface +>(null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface) : import("/node_modules/pkg/require").RequireInterface +>null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface : import("/node_modules/pkg/require").RequireInterface +>null as any : any +>null : null + +export const b = (null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface); +>b : any +>(null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface) : any +>null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface : any +>null as any : any +>null : null + +=== /other3.ts === +// Array instead of object-y thing +export type LocalInterface = +>LocalInterface : any + + & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface +>"resolution-mode" : "require" +>RequireInterface & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface : number +>RequireInterface : any + + & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; +>import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface : any +>import("pkg", [ {"resolution-mode": "import"} ]) : Promise<{ default: typeof import("/node_modules/pkg/import"); }> +>"pkg" : "pkg" +>[ {"resolution-mode": "import"} ] : { "resolution-mode": string; }[] +>{"resolution-mode": "import"} : { "resolution-mode": string; } +>"resolution-mode" : string +>"import" : "import" +>ImportInterface : any + +export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); +>a : any +>(null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface : any +>(null as any as import("pkg", [ {"resolution-mode": "require"} ]) : any +>null as any as import("pkg", [ {"resolution-mode": "require"} ] : any +>null as any : any +>null : null +>"resolution-mode" : "require" +>RequireInterface : any + +export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); +>b : any +>(null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface : any +>(null as any as import("pkg", [ {"resolution-mode": "import"} ]) : any +>null as any as import("pkg", [ {"resolution-mode": "import"} ] : any +>null as any : any +>null : null +>"resolution-mode" : "import" +>ImportInterface : any + +=== /other4.ts === +// Indirected assertion objecty-thing - not allowed +type Asserts1 = { assert: {"resolution-mode": "require"} }; +>Asserts1 : Asserts1 +>assert : { "resolution-mode": "require"; } +>"resolution-mode" : "require" + +type Asserts2 = { assert: {"resolution-mode": "import"} }; +>Asserts2 : Asserts2 +>assert : { "resolution-mode": "import"; } +>"resolution-mode" : "import" + +export type LocalInterface = +>LocalInterface : any + + & import("pkg", Asserts1).RequireInterface +>Asserts1 : any +>RequireInterface & import("pkg", Asserts2).ImportInterface : number +>RequireInterface : any + + & import("pkg", Asserts2).ImportInterface; +>import("pkg", Asserts2).ImportInterface : any +>import("pkg", Asserts2) : Promise<{ default: typeof import("/node_modules/pkg/import"); }> +>"pkg" : "pkg" +>Asserts2 : any +>ImportInterface : any + +export const a = (null as any as import("pkg", Asserts1).RequireInterface); +>a : any +>(null as any as import("pkg", : any +>null as any as import("pkg", : any +>null as any : any +>null : null +>Asserts1 : any +>RequireInterface : any + +export const b = (null as any as import("pkg", Asserts2).ImportInterface); +>b : any +>(null as any as import("pkg", : any +>null as any as import("pkg", : any +>null as any : any +>null : null +>Asserts2 : any +>ImportInterface : any + +=== /other5.ts === +export type LocalInterface = +>LocalInterface : any + + & import("pkg", { assert: {} }).RequireInterface + & import("pkg", { assert: {} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {} }).RequireInterface); +>a : import("/node_modules/pkg/require").RequireInterface +>(null as any as import("pkg", { assert: {} }).RequireInterface) : import("/node_modules/pkg/require").RequireInterface +>null as any as import("pkg", { assert: {} }).RequireInterface : import("/node_modules/pkg/require").RequireInterface +>null as any : any +>null : null + +export const b = (null as any as import("pkg", { assert: {} }).ImportInterface); +>b : any +>(null as any as import("pkg", { assert: {} }).ImportInterface) : any +>null as any as import("pkg", { assert: {} }).ImportInterface : any +>null as any : any +>null : null + diff --git a/tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit1.ts b/tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit1.ts new file mode 100644 index 0000000000000..5a9a0ef8cee2b --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit1.ts @@ -0,0 +1,29 @@ +// @noImplicitReferences: true +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: /node_modules/pkg/package.json +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +// @filename: /node_modules/pkg/import.d.ts +export interface ImportInterface {} +// @filename: /node_modules/pkg/require.d.ts +export interface RequireInterface {} +// @filename: /index.ts +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; diff --git a/tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit2.ts b/tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit2.ts new file mode 100644 index 0000000000000..7b819fddf490e --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesImportModeDeclarationEmit2.ts @@ -0,0 +1,34 @@ +// @noImplicitReferences: true +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: /node_modules/pkg/package.json +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +// @filename: /node_modules/pkg/import.d.ts +export interface ImportInterface {} +// @filename: /node_modules/pkg/require.d.ts +export interface RequireInterface {} +// @filename: /package.json +{ + "private": true, + "type": "module" +} +// @filename: /index.ts +import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; + +export interface LocalInterface extends RequireInterface, ImportInterface {} + +import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" }; +import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; +export interface Loc extends Req, Imp {} + +export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; +export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; diff --git a/tests/cases/conformance/node/nodeModulesImportModeDeclarationEmitErrors1.ts b/tests/cases/conformance/node/nodeModulesImportModeDeclarationEmitErrors1.ts new file mode 100644 index 0000000000000..1e475dfc63ad9 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesImportModeDeclarationEmitErrors1.ts @@ -0,0 +1,29 @@ +// @noImplicitReferences: true +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: /node_modules/pkg/package.json +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +// @filename: /node_modules/pkg/import.d.ts +export interface ImportInterface {} +// @filename: /node_modules/pkg/require.d.ts +export interface RequireInterface {} +// @filename: /index.ts +// incorrect mode +import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" }; +// not type-only +import { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; +// not exclusively type-only +import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; + +export interface LocalInterface extends RequireInterface, ImportInterface {} + + + diff --git a/tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmit1.ts b/tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmit1.ts new file mode 100644 index 0000000000000..41d64844e090a --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmit1.ts @@ -0,0 +1,24 @@ +// @noImplicitReferences: true +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: /node_modules/pkg/package.json +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +// @filename: /node_modules/pkg/import.d.ts +export interface ImportInterface {} +// @filename: /node_modules/pkg/require.d.ts +export interface RequireInterface {} +// @filename: /index.ts +export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); diff --git a/tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmitErrors1.ts b/tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmitErrors1.ts new file mode 100644 index 0000000000000..3a4204c15d8c4 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmitErrors1.ts @@ -0,0 +1,65 @@ +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: /node_modules/pkg/package.json +{ + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } +} +// @filename: /node_modules/pkg/import.d.ts +export interface ImportInterface {} +// @filename: /node_modules/pkg/require.d.ts +export interface RequireInterface {} +// @filename: /index.ts +export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); +// @filename: /other.ts +// missing assert: +export type LocalInterface = + & import("pkg", {"resolution-mode": "require"}).RequireInterface + & import("pkg", {"resolution-mode": "import"}).ImportInterface; + +export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); +export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); +// @filename: /other2.ts +// wrong assertion key +export type LocalInterface = + & import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface + & import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {"resolution-m0de": "require"} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {"resolution-m0de": "import"} }).ImportInterface); +// @filename: /other3.ts +// Array instead of object-y thing +export type LocalInterface = + & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface + & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; + +export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); +export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); +// @filename: /other4.ts +// Indirected assertion objecty-thing - not allowed +type Asserts1 = { assert: {"resolution-mode": "require"} }; +type Asserts2 = { assert: {"resolution-mode": "import"} }; + +export type LocalInterface = + & import("pkg", Asserts1).RequireInterface + & import("pkg", Asserts2).ImportInterface; + +export const a = (null as any as import("pkg", Asserts1).RequireInterface); +export const b = (null as any as import("pkg", Asserts2).ImportInterface); +// @filename: /other5.ts +export type LocalInterface = + & import("pkg", { assert: {} }).RequireInterface + & import("pkg", { assert: {} }).ImportInterface; + +export const a = (null as any as import("pkg", { assert: {} }).RequireInterface); +export const b = (null as any as import("pkg", { assert: {} }).ImportInterface);