From 4f50766e214ee9328b6ba20a4bde2d786d0f00a7 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 25 Sep 2018 11:02:20 -0700 Subject: [PATCH 1/5] Build better import paths from reexports if possible, issue error on node_modules import generation --- src/compiler/checker.ts | 67 +++++++++++++++++- src/compiler/diagnosticMessages.json | 4 ++ src/compiler/moduleSpecifiers.ts | 2 +- src/compiler/transformers/declarations.ts | 9 +++ src/compiler/types.ts | 8 ++- .../reference/api/tsserverlibrary.d.ts | 3 +- tests/baselines/reference/api/typescript.d.ts | 3 +- ...mitCommonJsModuleReferencedType.errors.txt | 28 ++++++++ ...arationEmitCommonJsModuleReferencedType.js | 5 -- ...clarationEmitReexportedSymlinkReference.js | 64 +++++++++++++++++ ...tionEmitReexportedSymlinkReference.symbols | 63 +++++++++++++++++ ...rationEmitReexportedSymlinkReference.types | 52 ++++++++++++++ ...larationEmitReexportedSymlinkReference2.js | 67 ++++++++++++++++++ ...ionEmitReexportedSymlinkReference2.symbols | 70 +++++++++++++++++++ ...ationEmitReexportedSymlinkReference2.types | 59 ++++++++++++++++ ...EmitReexportedSymlinkReference3.errors.txt | 60 ++++++++++++++++ ...larationEmitReexportedSymlinkReference3.js | 61 ++++++++++++++++ ...ionEmitReexportedSymlinkReference3.symbols | 65 +++++++++++++++++ ...ationEmitReexportedSymlinkReference3.types | 54 ++++++++++++++ ...eactTransitiveImportHasValidDeclaration.js | 2 +- ...tTransitiveImportHasValidDeclaration.types | 12 ++-- .../symbolLinkDeclarationEmitModuleNames.js | 2 +- ...symbolLinkDeclarationEmitModuleNames.types | 8 +-- ...olLinkDeclarationEmitModuleNamesRootDir.js | 2 +- ...inkDeclarationEmitModuleNamesRootDir.types | 8 +-- ...onEmit.multiFileBackReferenceToUnmapped.js | 4 +- ...clarationEmitReexportedSymlinkReference.ts | 56 +++++++++++++++ ...larationEmitReexportedSymlinkReference2.ts | 59 ++++++++++++++++ ...larationEmitReexportedSymlinkReference3.ts | 56 +++++++++++++++ 29 files changed, 923 insertions(+), 30 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference.js create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference.symbols create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference.types create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference2.symbols create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference2.types create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference3.symbols create mode 100644 tests/baselines/reference/declarationEmitReexportedSymlinkReference3.types create mode 100644 tests/cases/compiler/declarationEmitReexportedSymlinkReference.ts create mode 100644 tests/cases/compiler/declarationEmitReexportedSymlinkReference2.ts create mode 100644 tests/cases/compiler/declarationEmitReexportedSymlinkReference3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 691b994daae7d..621e2f8be9f94 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2551,6 +2551,40 @@ namespace ts { return getMergedSymbol(symbol.parent && getLateBoundSymbol(symbol.parent)); } + function getAlternativeContainingModules(symbol: Symbol, enclosingDeclaration: Node): Symbol[] | undefined { + const containingFile = getSourceFileOfNode(enclosingDeclaration); + if (containingFile && containingFile.imports) { + // Try to make an import using an import already in the enclosing file, if possible + let results: Symbol[] | undefined; + for (const importRef of containingFile.imports) { + if (nodeIsSynthesized(importRef)) continue; // Synthetic names can't be resolved by `resolveExternalModuleName` - they'll cause a debug assert if they error + const resolvedModule = resolveExternalModuleName(enclosingDeclaration, importRef); + if (!resolvedModule) continue; + const ref = getAliasForSymbolInContainer(resolvedModule, symbol); + if (!ref) continue; + results = append(results, resolvedModule); + } + if (results) { + return results; + } + } + const links = getSymbolLinks(symbol); + if (links.extendedContainers) { + return links.extendedContainers; + } + let results: Symbol[] = []; + // No results from files already being imported by this file - expand search (expensive, but not location-specific, so cached) + const otherFiles = host.getSourceFiles(); + for (const file of otherFiles) { + if (!isExternalModule(file)) continue; + const sym = getSymbolOfNode(file); + const ref = getAliasForSymbolInContainer(sym, symbol); + if (!ref) continue; + results = append(results, sym); + } + return links.extendedContainers = results; + } + /** * Attempts to find the symbol corresponding to the container a symbol is in - usually this * is just its' `.parent`, but for locals, this value is `undefined` @@ -2559,10 +2593,12 @@ namespace ts { const container = getParentOfSymbol(symbol); if (container) { const additionalContainers = mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer); + const reexportContainers = enclosingDeclaration && getAlternativeContainingModules(symbol, enclosingDeclaration); if (enclosingDeclaration && getAccessibleSymbolChain(container, enclosingDeclaration, SymbolFlags.Namespace, /*externalOnly*/ false)) { - return concatenate([container], additionalContainers); // This order expresses a preference for the real container if it is in scope + return concatenate(concatenate([container], additionalContainers), reexportContainers); // This order expresses a preference for the real container if it is in scope } - return append(additionalContainers, container); + const res = append(additionalContainers, container); + return concatenate(res, reexportContainers); } const candidates = mapDefined(symbol.declarations, d => !isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined); if (!length(candidates)) { @@ -3889,6 +3925,7 @@ namespace ts { // Go up and add our parent. const parents = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration); if (length(parents)) { + parents!.sort(sortByBestName); for (const parent of parents!) { const parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); if (parentChain) { @@ -3914,6 +3951,24 @@ namespace ts { return [symbol]; } } + + function sortByBestName(a: Symbol, b: Symbol) { + if (some(a.declarations, hasNonGlobalAugmentationExternalModuleSymbol) && some(b.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { + const specifierA = getSpecifierForModuleSymbol(a, context); + const specifierB = getSpecifierForModuleSymbol(b, context); + if (pathIsRelative(specifierA) === pathIsRelative(specifierB)) { + // Both relative or both non-relative, sort by number of parts + return moduleSpecifiers.countPathComponents(specifierA) - moduleSpecifiers.countPathComponents(specifierB); + } + if (pathIsRelative(specifierB)) { + // A is non-relative, B is relative: prefer A + return -1; + } + // A is relative, B is non-relative: prefer B + return 1; + } + return 0; + } } function typeParametersToTypeParameterDeclarations(symbol: Symbol, context: NodeBuilderContext) { @@ -4016,6 +4071,14 @@ namespace ts { 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); + if (!(context.flags & NodeBuilderFlags.AllowNodeModulesRelativePaths) && getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeJs && 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 lit = createLiteralTypeNode(createLiteral(specifier)); if (context.tracker.trackExternalModuleSymbolOfImportTypeNode) context.tracker.trackExternalModuleSymbolOfImportTypeNode(chain[0]); context.approximateLength += specifier.length + 10; // specifier + import("") diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 706a35527653e..6ecd6c768c275 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2489,6 +2489,10 @@ "category": "Error", "code": 2734 }, + "The inferred type of '{0}' requires a reference to a module at '{1}' to name, which would likely break on type redistribution. A type annotation is necessary.": { + "category": "Error", + "code": 2735 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index e50aaf994533a..5d60800a30756 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -139,7 +139,7 @@ namespace ts.moduleSpecifiers { return isPathRelativeToParent(nonRelative) || countPathComponents(relativePath) < countPathComponents(nonRelative) ? relativePath : nonRelative; } - function countPathComponents(path: string): number { + export function countPathComponents(path: string): number { let count = 0; for (let i = startsWith(path, "./") ? 2 : 0; i < path.length; i++) { if (path.charCodeAt(i) === CharacterCodes.slash) count++; diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 5312efb5aac03..9e9665475f2af 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -45,6 +45,7 @@ namespace ts { reportInaccessibleThisError, reportInaccessibleUniqueSymbolError, reportPrivateInBaseOfClassExpression, + reportLikelyUnsafeImportRequiredError, moduleResolverHost: host, trackReferencedAmbientModule, trackExternalModuleSymbolOfImportTypeNode @@ -153,6 +154,14 @@ namespace ts { } } + function reportLikelyUnsafeImportRequiredError(specifier: string) { + if (errorNameNode) { + context.addDiagnostic(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_requires_a_reference_to_a_module_at_1_to_name_which_would_likely_break_on_type_redistribution_A_type_annotation_is_necessary, + declarationNameToString(errorNameNode), + specifier)); + } + } + function transformRoot(node: Bundle): Bundle; function transformRoot(node: SourceFile): SourceFile; function transformRoot(node: SourceFile | Bundle): SourceFile | Bundle; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 176f259e0746b..23ce5c49a19ad 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3176,13 +3176,17 @@ namespace ts { AllowUniqueESSymbolType = 1 << 20, AllowEmptyIndexInfoType = 1 << 21, - IgnoreErrors = AllowThisInObjectLiteral | AllowQualifedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple | AllowEmptyIndexInfoType, + // Errors (cont.) + AllowNodeModulesRelativePaths = 1 << 26, + + IgnoreErrors = AllowThisInObjectLiteral | AllowQualifedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple | AllowEmptyIndexInfoType | AllowNodeModulesRelativePaths, // State InObjectTypeLiteral = 1 << 22, InTypeAlias = 1 << 23, // Writing type in type alias declaration InInitialEntityName = 1 << 24, // Set when writing the LHS of an entity name or entity name expression InReverseMappedType = 1 << 25, + } // Ensure the shared flags between this and `NodeBuilderFlags` stay in alignment @@ -3557,6 +3561,7 @@ namespace ts { originatingImport?: ImportDeclaration | ImportCall; // Import declaration which produced the symbol, present if the symbol is marked as uncallable but had call signatures in `resolveESModuleSymbol` lateSymbol?: Symbol; // Late-bound symbol for a computed property specifierCache?: Map; // For symbols corresponding to external modules, a cache of incoming path -> module specifier name mappings + extendedContainers?: Symbol[]; // Containers (other than the parent) which this symbol is aliased in } /* @internal */ @@ -5378,6 +5383,7 @@ namespace ts { reportInaccessibleThisError?(): void; reportPrivateInBaseOfClassExpression?(propertyName: string): void; reportInaccessibleUniqueSymbolError?(): void; + reportLikelyUnsafeImportRequiredError?(specifier: string): void; moduleResolverHost?: EmitHost; trackReferencedAmbientModule?(decl: ModuleDeclaration, symbol: Symbol): void; trackExternalModuleSymbolOfImportTypeNode?(symbol: Symbol): void; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 68926b43c81ce..42cebca2b263a 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1979,7 +1979,8 @@ declare namespace ts { AllowEmptyTuple = 524288, AllowUniqueESSymbolType = 1048576, AllowEmptyIndexInfoType = 2097152, - IgnoreErrors = 3112960, + AllowNodeModulesRelativePaths = 67108864, + IgnoreErrors = 70221824, InObjectTypeLiteral = 4194304, InTypeAlias = 8388608, InInitialEntityName = 16777216, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 4b01738783d9c..3fed183868e56 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1979,7 +1979,8 @@ declare namespace ts { AllowEmptyTuple = 524288, AllowUniqueESSymbolType = 1048576, AllowEmptyIndexInfoType = 2097152, - IgnoreErrors = 3112960, + AllowNodeModulesRelativePaths = 67108864, + IgnoreErrors = 70221824, InObjectTypeLiteral = 4194304, InTypeAlias = 8388608, InInitialEntityName = 16777216, diff --git a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt new file mode 100644 index 0000000000000..6f69b9fb7e203 --- /dev/null +++ b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/r/entry.ts(3,14): error TS2735: The inferred type of 'x' requires a reference to a module at 'foo/node_modules/nested' to name, which would likely break on type redistribution. A type annotation is necessary. + + +==== tests/cases/compiler/r/node_modules/foo/node_modules/nested/index.d.ts (0 errors) ==== + export interface NestedProps {} +==== tests/cases/compiler/r/node_modules/foo/other/index.d.ts (0 errors) ==== + export interface OtherIndexProps {} +==== tests/cases/compiler/r/node_modules/foo/other.d.ts (0 errors) ==== + export interface OtherProps {} +==== tests/cases/compiler/r/node_modules/foo/index.d.ts (0 errors) ==== + import { OtherProps } from "./other"; + import { OtherIndexProps } from "./other/index"; + import { NestedProps } from "nested"; + export interface SomeProps {} + + export function foo(): [SomeProps, OtherProps, OtherIndexProps, NestedProps]; +==== tests/cases/compiler/node_modules/root/index.d.ts (0 errors) ==== + export interface RootProps {} + + export function bar(): RootProps; +==== tests/cases/compiler/r/entry.ts (1 errors) ==== + import { foo } from "foo"; + import { bar } from "root"; + export const x = foo(); + ~ +!!! error TS2735: The inferred type of 'x' requires a reference to a module at 'foo/node_modules/nested' to name, which would likely break on type redistribution. A type annotation is necessary. + export const y = bar(); + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.js b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.js index 1e32c5c4c262b..5f1d474f75b87 100644 --- a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.js +++ b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.js @@ -31,8 +31,3 @@ var foo_1 = require("foo"); var root_1 = require("root"); exports.x = foo_1.foo(); exports.y = root_1.bar(); - - -//// [entry.d.ts] -export declare const x: [import("foo").SomeProps, import("foo/other").OtherProps, import("foo/other/index").OtherIndexProps, import("foo/node_modules/nested").NestedProps]; -export declare const y: import("root").RootProps; diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js new file mode 100644 index 0000000000000..0683f21cd575a --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.js @@ -0,0 +1,64 @@ +//// [tests/cases/compiler/declarationEmitReexportedSymlinkReference.ts] //// + +//// [index.d.ts] +export * from './types'; +//// [types.d.ts] +export declare type A = { + id: string; +}; +export declare type B = { + id: number; +}; +export declare type IdType = A | B; +export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; +} +//// [package.json] +{ + "name": "@raymondfeng/pkg1", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +//// [index.d.ts] +export * from './types'; +//// [types.d.ts] +export * from '@raymondfeng/pkg1'; +//// [package.json] +{ + "name": "@raymondfeng/pkg2", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +//// [index.ts] +export * from './keys'; +//// [keys.ts] +import {MetadataAccessor} from "@raymondfeng/pkg2"; + +export const ADMIN = MetadataAccessor.create('1'); + +//// [keys.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var pkg2_1 = require("@raymondfeng/pkg2"); +exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); +//// [index.js] +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +Object.defineProperty(exports, "__esModule", { value: true }); +__export(require("./keys")); + + +//// [keys.d.ts] +import { MetadataAccessor } from "@raymondfeng/pkg2"; +export declare const ADMIN: MetadataAccessor; +//// [index.d.ts] +export * from './keys'; diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference.symbols b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.symbols new file mode 100644 index 0000000000000..4006ea88a86e1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.symbols @@ -0,0 +1,63 @@ +=== tests/cases/compiler/monorepo/pkg1/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg1/dist/types.d.ts === +export declare type A = { +>A : Symbol(A, Decl(types.d.ts, 0, 0)) + + id: string; +>id : Symbol(id, Decl(types.d.ts, 0, 25)) + +}; +export declare type B = { +>B : Symbol(B, Decl(types.d.ts, 2, 2)) + + id: number; +>id : Symbol(id, Decl(types.d.ts, 3, 25)) + +}; +export declare type IdType = A | B; +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>A : Symbol(A, Decl(types.d.ts, 0, 0)) +>B : Symbol(B, Decl(types.d.ts, 2, 2)) + +export declare class MetadataAccessor { +>MetadataAccessor : Symbol(MetadataAccessor, Decl(types.d.ts, 6, 35)) +>T : Symbol(T, Decl(types.d.ts, 7, 38)) +>D : Symbol(D, Decl(types.d.ts, 7, 40)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) + + readonly key: string; +>key : Symbol(MetadataAccessor.key, Decl(types.d.ts, 7, 69)) + + private constructor(); + toString(): string; +>toString : Symbol(MetadataAccessor.toString, Decl(types.d.ts, 9, 26)) + + static create(key: string): MetadataAccessor; +>create : Symbol(MetadataAccessor.create, Decl(types.d.ts, 10, 23)) +>T : Symbol(T, Decl(types.d.ts, 11, 18)) +>D : Symbol(D, Decl(types.d.ts, 11, 20)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>key : Symbol(key, Decl(types.d.ts, 11, 48)) +>MetadataAccessor : Symbol(MetadataAccessor, Decl(types.d.ts, 6, 35)) +>T : Symbol(T, Decl(types.d.ts, 11, 18)) +>D : Symbol(D, Decl(types.d.ts, 11, 20)) +} +=== tests/cases/compiler/monorepo/pkg2/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg2/dist/types.d.ts === +export * from '@raymondfeng/pkg1'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg3/src/index.ts === +export * from './keys'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg3/src/keys.ts === +import {MetadataAccessor} from "@raymondfeng/pkg2"; +>MetadataAccessor : Symbol(MetadataAccessor, Decl(keys.ts, 0, 8)) + +export const ADMIN = MetadataAccessor.create('1'); +>ADMIN : Symbol(ADMIN, Decl(keys.ts, 2, 12)) +>MetadataAccessor.create : Symbol(MetadataAccessor.create, Decl(types.d.ts, 10, 23)) +>MetadataAccessor : Symbol(MetadataAccessor, Decl(keys.ts, 0, 8)) +>create : Symbol(MetadataAccessor.create, Decl(types.d.ts, 10, 23)) + diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference.types b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.types new file mode 100644 index 0000000000000..50c770d525718 --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference.types @@ -0,0 +1,52 @@ +=== tests/cases/compiler/monorepo/pkg1/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg1/dist/types.d.ts === +export declare type A = { +>A : A + + id: string; +>id : string + +}; +export declare type B = { +>B : B + + id: number; +>id : number + +}; +export declare type IdType = A | B; +>IdType : IdType + +export declare class MetadataAccessor { +>MetadataAccessor : MetadataAccessor + + readonly key: string; +>key : string + + private constructor(); + toString(): string; +>toString : () => string + + static create(key: string): MetadataAccessor; +>create : (key: string) => MetadataAccessor +>key : string +} +=== tests/cases/compiler/monorepo/pkg2/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg2/dist/types.d.ts === +export * from '@raymondfeng/pkg1'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg3/src/index.ts === +export * from './keys'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg3/src/keys.ts === +import {MetadataAccessor} from "@raymondfeng/pkg2"; +>MetadataAccessor : typeof MetadataAccessor + +export const ADMIN = MetadataAccessor.create('1'); +>ADMIN : MetadataAccessor +>MetadataAccessor.create('1') : MetadataAccessor +>MetadataAccessor.create : (key: string) => MetadataAccessor +>MetadataAccessor : typeof MetadataAccessor +>create : (key: string) => MetadataAccessor +>'1' : "1" + diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js new file mode 100644 index 0000000000000..5403cb95effe5 --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.js @@ -0,0 +1,67 @@ +//// [tests/cases/compiler/declarationEmitReexportedSymlinkReference2.ts] //// + +//// [index.d.ts] +export * from './types'; +//// [types.d.ts] +export declare type A = { + id: string; +}; +export declare type B = { + id: number; +}; +export declare type IdType = A | B; +export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; +} +//// [package.json] +{ + "name": "@raymondfeng/pkg1", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +//// [index.d.ts] +import "./secondary"; +export * from './types'; +//// [types.d.ts] +export {MetadataAccessor} from '@raymondfeng/pkg1'; +//// [secondary.d.ts] +export {IdType} from '@raymondfeng/pkg1'; +//// [package.json] +{ + "name": "@raymondfeng/pkg2", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +//// [index.ts] +export * from './keys'; +//// [keys.ts] +import {MetadataAccessor} from "@raymondfeng/pkg2"; + +export const ADMIN = MetadataAccessor.create('1'); + +//// [keys.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var pkg2_1 = require("@raymondfeng/pkg2"); +exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); +//// [index.js] +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +Object.defineProperty(exports, "__esModule", { value: true }); +__export(require("./keys")); + + +//// [keys.d.ts] +import { MetadataAccessor } from "@raymondfeng/pkg2"; +export declare const ADMIN: MetadataAccessor; +//// [index.d.ts] +export * from './keys'; diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.symbols b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.symbols new file mode 100644 index 0000000000000..683969e356f33 --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.symbols @@ -0,0 +1,70 @@ +=== tests/cases/compiler/monorepo/pkg1/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg1/dist/types.d.ts === +export declare type A = { +>A : Symbol(A, Decl(types.d.ts, 0, 0)) + + id: string; +>id : Symbol(id, Decl(types.d.ts, 0, 25)) + +}; +export declare type B = { +>B : Symbol(B, Decl(types.d.ts, 2, 2)) + + id: number; +>id : Symbol(id, Decl(types.d.ts, 3, 25)) + +}; +export declare type IdType = A | B; +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>A : Symbol(A, Decl(types.d.ts, 0, 0)) +>B : Symbol(B, Decl(types.d.ts, 2, 2)) + +export declare class MetadataAccessor { +>MetadataAccessor : Symbol(MetadataAccessor, Decl(types.d.ts, 6, 35)) +>T : Symbol(T, Decl(types.d.ts, 7, 38)) +>D : Symbol(D, Decl(types.d.ts, 7, 40)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) + + readonly key: string; +>key : Symbol(MetadataAccessor.key, Decl(types.d.ts, 7, 69)) + + private constructor(); + toString(): string; +>toString : Symbol(MetadataAccessor.toString, Decl(types.d.ts, 9, 26)) + + static create(key: string): MetadataAccessor; +>create : Symbol(MetadataAccessor.create, Decl(types.d.ts, 10, 23)) +>T : Symbol(T, Decl(types.d.ts, 11, 18)) +>D : Symbol(D, Decl(types.d.ts, 11, 20)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>key : Symbol(key, Decl(types.d.ts, 11, 48)) +>MetadataAccessor : Symbol(MetadataAccessor, Decl(types.d.ts, 6, 35)) +>T : Symbol(T, Decl(types.d.ts, 11, 18)) +>D : Symbol(D, Decl(types.d.ts, 11, 20)) +} +=== tests/cases/compiler/monorepo/pkg2/dist/index.d.ts === +import "./secondary"; +No type information for this code.export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg2/dist/types.d.ts === +export {MetadataAccessor} from '@raymondfeng/pkg1'; +>MetadataAccessor : Symbol(MetadataAccessor, Decl(types.d.ts, 0, 8)) + +=== tests/cases/compiler/monorepo/pkg2/dist/secondary.d.ts === +export {IdType} from '@raymondfeng/pkg1'; +>IdType : Symbol(IdType, Decl(secondary.d.ts, 0, 8)) + +=== tests/cases/compiler/monorepo/pkg3/src/index.ts === +export * from './keys'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg3/src/keys.ts === +import {MetadataAccessor} from "@raymondfeng/pkg2"; +>MetadataAccessor : Symbol(MetadataAccessor, Decl(keys.ts, 0, 8)) + +export const ADMIN = MetadataAccessor.create('1'); +>ADMIN : Symbol(ADMIN, Decl(keys.ts, 2, 12)) +>MetadataAccessor.create : Symbol(MetadataAccessor.create, Decl(types.d.ts, 10, 23)) +>MetadataAccessor : Symbol(MetadataAccessor, Decl(keys.ts, 0, 8)) +>create : Symbol(MetadataAccessor.create, Decl(types.d.ts, 10, 23)) + diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.types b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.types new file mode 100644 index 0000000000000..1ecb9e7592298 --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference2.types @@ -0,0 +1,59 @@ +=== tests/cases/compiler/monorepo/pkg1/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg1/dist/types.d.ts === +export declare type A = { +>A : A + + id: string; +>id : string + +}; +export declare type B = { +>B : B + + id: number; +>id : number + +}; +export declare type IdType = A | B; +>IdType : IdType + +export declare class MetadataAccessor { +>MetadataAccessor : MetadataAccessor + + readonly key: string; +>key : string + + private constructor(); + toString(): string; +>toString : () => string + + static create(key: string): MetadataAccessor; +>create : (key: string) => MetadataAccessor +>key : string +} +=== tests/cases/compiler/monorepo/pkg2/dist/index.d.ts === +import "./secondary"; +No type information for this code.export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg2/dist/types.d.ts === +export {MetadataAccessor} from '@raymondfeng/pkg1'; +>MetadataAccessor : typeof import("tests/cases/compiler/monorepo/pkg1/dist/index").MetadataAccessor + +=== tests/cases/compiler/monorepo/pkg2/dist/secondary.d.ts === +export {IdType} from '@raymondfeng/pkg1'; +>IdType : any + +=== tests/cases/compiler/monorepo/pkg3/src/index.ts === +export * from './keys'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg3/src/keys.ts === +import {MetadataAccessor} from "@raymondfeng/pkg2"; +>MetadataAccessor : typeof MetadataAccessor + +export const ADMIN = MetadataAccessor.create('1'); +>ADMIN : MetadataAccessor +>MetadataAccessor.create('1') : MetadataAccessor +>MetadataAccessor.create : (key: string) => MetadataAccessor +>MetadataAccessor : typeof MetadataAccessor +>create : (key: string) => MetadataAccessor +>'1' : "1" + diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt new file mode 100644 index 0000000000000..aa55957c5687f --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt @@ -0,0 +1,60 @@ +tests/cases/compiler/monorepo/pkg3/src/keys.ts(3,14): error TS2735: The inferred type of 'ADMIN' requires a reference to a module at '../../pkg2/node_modules/@raymondfeng/pkg1/dist' to name, which would likely break on type redistribution. A type annotation is necessary. + + +==== tests/cases/compiler/monorepo/pkg3/tsconfig.json (0 errors) ==== + { + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "target": "es5", + "module": "commonjs", + "strict": true, + "esModuleInterop": true, + "declaration": true + } + } + +==== tests/cases/compiler/monorepo/pkg1/dist/index.d.ts (0 errors) ==== + export * from './types'; +==== tests/cases/compiler/monorepo/pkg1/dist/types.d.ts (0 errors) ==== + export declare type A = { + id: string; + }; + export declare type B = { + id: number; + }; + export declare type IdType = A | B; + export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; + } +==== tests/cases/compiler/monorepo/pkg1/package.json (0 errors) ==== + { + "name": "@raymondfeng/pkg1", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" + } +==== tests/cases/compiler/monorepo/pkg2/dist/index.d.ts (0 errors) ==== + export * from './types'; +==== tests/cases/compiler/monorepo/pkg2/dist/types.d.ts (0 errors) ==== + export {MetadataAccessor} from '@raymondfeng/pkg1'; +==== tests/cases/compiler/monorepo/pkg2/package.json (0 errors) ==== + { + "name": "@raymondfeng/pkg2", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" + } +==== tests/cases/compiler/monorepo/pkg3/src/index.ts (0 errors) ==== + export * from './keys'; +==== tests/cases/compiler/monorepo/pkg3/src/keys.ts (1 errors) ==== + import {MetadataAccessor} from "@raymondfeng/pkg2"; + + export const ADMIN = MetadataAccessor.create('1'); + ~~~~~ +!!! error TS2735: The inferred type of 'ADMIN' requires a reference to a module at '../../pkg2/node_modules/@raymondfeng/pkg1/dist' to name, which would likely break on type redistribution. A type annotation is necessary. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js new file mode 100644 index 0000000000000..2ac5a9fffbd0c --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js @@ -0,0 +1,61 @@ +//// [tests/cases/compiler/declarationEmitReexportedSymlinkReference3.ts] //// + +//// [index.d.ts] +export * from './types'; +//// [types.d.ts] +export declare type A = { + id: string; +}; +export declare type B = { + id: number; +}; +export declare type IdType = A | B; +export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; +} +//// [package.json] +{ + "name": "@raymondfeng/pkg1", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +//// [index.d.ts] +export * from './types'; +//// [types.d.ts] +export {MetadataAccessor} from '@raymondfeng/pkg1'; +//// [package.json] +{ + "name": "@raymondfeng/pkg2", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +//// [index.ts] +export * from './keys'; +//// [keys.ts] +import {MetadataAccessor} from "@raymondfeng/pkg2"; + +export const ADMIN = MetadataAccessor.create('1'); + +//// [keys.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var pkg2_1 = require("@raymondfeng/pkg2"); +exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); +//// [index.js] +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +Object.defineProperty(exports, "__esModule", { value: true }); +__export(require("./keys")); + + +//// [index.d.ts] +export * from './keys'; diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.symbols b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.symbols new file mode 100644 index 0000000000000..df33b515a8d44 --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.symbols @@ -0,0 +1,65 @@ +=== tests/cases/compiler/monorepo/pkg1/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg1/dist/types.d.ts === +export declare type A = { +>A : Symbol(A, Decl(types.d.ts, 0, 0)) + + id: string; +>id : Symbol(id, Decl(types.d.ts, 0, 25)) + +}; +export declare type B = { +>B : Symbol(B, Decl(types.d.ts, 2, 2)) + + id: number; +>id : Symbol(id, Decl(types.d.ts, 3, 25)) + +}; +export declare type IdType = A | B; +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>A : Symbol(A, Decl(types.d.ts, 0, 0)) +>B : Symbol(B, Decl(types.d.ts, 2, 2)) + +export declare class MetadataAccessor { +>MetadataAccessor : Symbol(MetadataAccessor, Decl(types.d.ts, 6, 35)) +>T : Symbol(T, Decl(types.d.ts, 7, 38)) +>D : Symbol(D, Decl(types.d.ts, 7, 40)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) + + readonly key: string; +>key : Symbol(MetadataAccessor.key, Decl(types.d.ts, 7, 69)) + + private constructor(); + toString(): string; +>toString : Symbol(MetadataAccessor.toString, Decl(types.d.ts, 9, 26)) + + static create(key: string): MetadataAccessor; +>create : Symbol(MetadataAccessor.create, Decl(types.d.ts, 10, 23)) +>T : Symbol(T, Decl(types.d.ts, 11, 18)) +>D : Symbol(D, Decl(types.d.ts, 11, 20)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>IdType : Symbol(IdType, Decl(types.d.ts, 5, 2)) +>key : Symbol(key, Decl(types.d.ts, 11, 48)) +>MetadataAccessor : Symbol(MetadataAccessor, Decl(types.d.ts, 6, 35)) +>T : Symbol(T, Decl(types.d.ts, 11, 18)) +>D : Symbol(D, Decl(types.d.ts, 11, 20)) +} +=== tests/cases/compiler/monorepo/pkg2/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg2/dist/types.d.ts === +export {MetadataAccessor} from '@raymondfeng/pkg1'; +>MetadataAccessor : Symbol(MetadataAccessor, Decl(types.d.ts, 0, 8)) + +=== tests/cases/compiler/monorepo/pkg3/src/index.ts === +export * from './keys'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg3/src/keys.ts === +import {MetadataAccessor} from "@raymondfeng/pkg2"; +>MetadataAccessor : Symbol(MetadataAccessor, Decl(keys.ts, 0, 8)) + +export const ADMIN = MetadataAccessor.create('1'); +>ADMIN : Symbol(ADMIN, Decl(keys.ts, 2, 12)) +>MetadataAccessor.create : Symbol(MetadataAccessor.create, Decl(types.d.ts, 10, 23)) +>MetadataAccessor : Symbol(MetadataAccessor, Decl(keys.ts, 0, 8)) +>create : Symbol(MetadataAccessor.create, Decl(types.d.ts, 10, 23)) + diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.types b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.types new file mode 100644 index 0000000000000..e3f8347888466 --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.types @@ -0,0 +1,54 @@ +=== tests/cases/compiler/monorepo/pkg1/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg1/dist/types.d.ts === +export declare type A = { +>A : A + + id: string; +>id : string + +}; +export declare type B = { +>B : B + + id: number; +>id : number + +}; +export declare type IdType = A | B; +>IdType : IdType + +export declare class MetadataAccessor { +>MetadataAccessor : MetadataAccessor + + readonly key: string; +>key : string + + private constructor(); + toString(): string; +>toString : () => string + + static create(key: string): MetadataAccessor; +>create : (key: string) => MetadataAccessor +>key : string +} +=== tests/cases/compiler/monorepo/pkg2/dist/index.d.ts === +export * from './types'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg2/dist/types.d.ts === +export {MetadataAccessor} from '@raymondfeng/pkg1'; +>MetadataAccessor : typeof import("tests/cases/compiler/monorepo/pkg1/dist/index").MetadataAccessor + +=== tests/cases/compiler/monorepo/pkg3/src/index.ts === +export * from './keys'; +No type information for this code.=== tests/cases/compiler/monorepo/pkg3/src/keys.ts === +import {MetadataAccessor} from "@raymondfeng/pkg2"; +>MetadataAccessor : typeof MetadataAccessor + +export const ADMIN = MetadataAccessor.create('1'); +>ADMIN : MetadataAccessor +>MetadataAccessor.create('1') : MetadataAccessor +>MetadataAccessor.create : (key: string) => MetadataAccessor +>MetadataAccessor : typeof MetadataAccessor +>create : (key: string) => MetadataAccessor +>'1' : "1" + diff --git a/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.js b/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.js index 4cd606eae0ed0..526240701e324 100644 --- a/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.js +++ b/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.js @@ -44,5 +44,5 @@ exports["default"] = Form; //// [index.d.ts] /// -declare const Form: import("create-emotion-styled/types/react").StyledOtherComponent<{}, import("react").DetailedHTMLProps, HTMLDivElement>, any>; +declare const Form: import("create-emotion-styled").StyledOtherComponent<{}, import("react").DetailedHTMLProps, HTMLDivElement>, any>; export default Form; diff --git a/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.types b/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.types index b50eb1e30bb9f..07eacfb8f4d9b 100644 --- a/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.types +++ b/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.types @@ -42,18 +42,18 @@ export default function styled(tag: string): (o: object) => StyledOtherComponent === tests/cases/compiler/index.ts === import styled from "react-emotion" ->styled : (tag: string) => (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/types/react/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>styled : (tag: string) => (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> const Form = styled('div')({ color: "red" }) ->Form : import("tests/cases/compiler/node_modules/create-emotion-styled/types/react/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> ->styled('div')({ color: "red" }) : import("tests/cases/compiler/node_modules/create-emotion-styled/types/react/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> ->styled('div') : (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/types/react/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> ->styled : (tag: string) => (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/types/react/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>Form : import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>styled('div')({ color: "red" }) : import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>styled('div') : (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>styled : (tag: string) => (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> >'div' : "div" >{ color: "red" } : { color: string; } >color : string >"red" : "red" export default Form ->Form : import("tests/cases/compiler/node_modules/create-emotion-styled/types/react/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>Form : import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> diff --git a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js index a154c443de4d8..8cf2fab6fb4b5 100644 --- a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js +++ b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.js @@ -72,4 +72,4 @@ import { Constructor } from "@loopback/context"; export declare type ControllerClass = Constructor; //// [usage.d.ts] import { BindingKey } from '@loopback/context'; -export declare const CONTROLLER_CLASS: BindingKey>; +export declare const CONTROLLER_CLASS: BindingKey>; diff --git a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.types b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.types index 1101327b28377..d9f60d9545c9e 100644 --- a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.types +++ b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNames.types @@ -13,11 +13,11 @@ import { BindingKey } from '@loopback/context'; >BindingKey : typeof BindingKey export const CONTROLLER_CLASS = BindingKey.create(null as any); // line in question ->CONTROLLER_CLASS : BindingKey> ->BindingKey.create(null as any) : BindingKey> ->BindingKey.create : >(ctor: T) => BindingKey +>CONTROLLER_CLASS : BindingKey> +>BindingKey.create(null as any) : BindingKey> +>BindingKey.create : >(ctor: T) => BindingKey >BindingKey : typeof BindingKey ->create : >(ctor: T) => BindingKey +>create : >(ctor: T) => BindingKey >null as any : any >null : null diff --git a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNamesRootDir.js b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNamesRootDir.js index 124e8420d7e86..95b245269554b 100644 --- a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNamesRootDir.js +++ b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNamesRootDir.js @@ -39,4 +39,4 @@ import { Constructor } from "@loopback/context"; export declare type ControllerClass = Constructor; //// [usage.d.ts] import { BindingKey } from '@loopback/context'; -export declare const CONTROLLER_CLASS: BindingKey>; +export declare const CONTROLLER_CLASS: BindingKey>; diff --git a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNamesRootDir.types b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNamesRootDir.types index 7011a700ab3c9..bb6a91a129eab 100644 --- a/tests/baselines/reference/symbolLinkDeclarationEmitModuleNamesRootDir.types +++ b/tests/baselines/reference/symbolLinkDeclarationEmitModuleNamesRootDir.types @@ -37,11 +37,11 @@ import { BindingKey } from '@loopback/context'; >BindingKey : typeof BindingKey export const CONTROLLER_CLASS = BindingKey.create(null as any); // line in question ->CONTROLLER_CLASS : BindingKey> ->BindingKey.create(null as any) : BindingKey> ->BindingKey.create : >(ctor: T) => BindingKey +>CONTROLLER_CLASS : BindingKey> +>BindingKey.create(null as any) : BindingKey> +>BindingKey.create : >(ctor: T) => BindingKey >BindingKey : typeof BindingKey ->create : >(ctor: T) => BindingKey +>create : >(ctor: T) => BindingKey >null as any : any >null : null diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.js b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.js index fb7dfd74b2d45..b7cfdf92a6cd7 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.js +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.js @@ -41,5 +41,5 @@ exports.va2 = other_1.fa(); //// [main.d.ts] -export declare const va: import("ext/other").A2; -export declare const va2: import("ext/other").A2; +export declare const va: import("ext").A2; +export declare const va2: import("ext").A2; diff --git a/tests/cases/compiler/declarationEmitReexportedSymlinkReference.ts b/tests/cases/compiler/declarationEmitReexportedSymlinkReference.ts new file mode 100644 index 0000000000000..d0f58e2ede798 --- /dev/null +++ b/tests/cases/compiler/declarationEmitReexportedSymlinkReference.ts @@ -0,0 +1,56 @@ +// @filename: monorepo/pkg1/dist/index.d.ts +export * from './types'; +// @filename: monorepo/pkg1/dist/types.d.ts +export declare type A = { + id: string; +}; +export declare type B = { + id: number; +}; +export declare type IdType = A | B; +export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; +} +// @filename: monorepo/pkg1/package.json +{ + "name": "@raymondfeng/pkg1", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +// @filename: monorepo/pkg2/dist/index.d.ts +export * from './types'; +// @filename: monorepo/pkg2/dist/types.d.ts +export * from '@raymondfeng/pkg1'; +// @filename: monorepo/pkg2/package.json +{ + "name": "@raymondfeng/pkg2", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +// @filename: monorepo/pkg3/src/index.ts +export * from './keys'; +// @filename: monorepo/pkg3/src/keys.ts +import {MetadataAccessor} from "@raymondfeng/pkg2"; + +export const ADMIN = MetadataAccessor.create('1'); +// @filename: monorepo/pkg3/tsconfig.json +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "target": "es5", + "module": "commonjs", + "strict": true, + "esModuleInterop": true, + "declaration": true + } +} +// @link: tests/cases/compiler/monorepo/pkg1 -> tests/cases/compiler/monorepo/pkg2/node_modules/@raymondfeng/pkg1 +// @link: tests/cases/compiler/monorepo/pkg2 -> tests/cases/compiler/monorepo/pkg3/node_modules/@raymondfeng/pkg2 diff --git a/tests/cases/compiler/declarationEmitReexportedSymlinkReference2.ts b/tests/cases/compiler/declarationEmitReexportedSymlinkReference2.ts new file mode 100644 index 0000000000000..764a2c3f0ba28 --- /dev/null +++ b/tests/cases/compiler/declarationEmitReexportedSymlinkReference2.ts @@ -0,0 +1,59 @@ +// @filename: monorepo/pkg1/dist/index.d.ts +export * from './types'; +// @filename: monorepo/pkg1/dist/types.d.ts +export declare type A = { + id: string; +}; +export declare type B = { + id: number; +}; +export declare type IdType = A | B; +export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; +} +// @filename: monorepo/pkg1/package.json +{ + "name": "@raymondfeng/pkg1", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +// @filename: monorepo/pkg2/dist/index.d.ts +import "./secondary"; +export * from './types'; +// @filename: monorepo/pkg2/dist/types.d.ts +export {MetadataAccessor} from '@raymondfeng/pkg1'; +// @filename: monorepo/pkg2/dist/secondary.d.ts +export {IdType} from '@raymondfeng/pkg1'; +// @filename: monorepo/pkg2/package.json +{ + "name": "@raymondfeng/pkg2", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +// @filename: monorepo/pkg3/src/index.ts +export * from './keys'; +// @filename: monorepo/pkg3/src/keys.ts +import {MetadataAccessor} from "@raymondfeng/pkg2"; + +export const ADMIN = MetadataAccessor.create('1'); +// @filename: monorepo/pkg3/tsconfig.json +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "target": "es5", + "module": "commonjs", + "strict": true, + "esModuleInterop": true, + "declaration": true + } +} +// @link: tests/cases/compiler/monorepo/pkg1 -> tests/cases/compiler/monorepo/pkg2/node_modules/@raymondfeng/pkg1 +// @link: tests/cases/compiler/monorepo/pkg2 -> tests/cases/compiler/monorepo/pkg3/node_modules/@raymondfeng/pkg2 diff --git a/tests/cases/compiler/declarationEmitReexportedSymlinkReference3.ts b/tests/cases/compiler/declarationEmitReexportedSymlinkReference3.ts new file mode 100644 index 0000000000000..e65b752a3a0e9 --- /dev/null +++ b/tests/cases/compiler/declarationEmitReexportedSymlinkReference3.ts @@ -0,0 +1,56 @@ +// @filename: monorepo/pkg1/dist/index.d.ts +export * from './types'; +// @filename: monorepo/pkg1/dist/types.d.ts +export declare type A = { + id: string; +}; +export declare type B = { + id: number; +}; +export declare type IdType = A | B; +export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; +} +// @filename: monorepo/pkg1/package.json +{ + "name": "@raymondfeng/pkg1", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +// @filename: monorepo/pkg2/dist/index.d.ts +export * from './types'; +// @filename: monorepo/pkg2/dist/types.d.ts +export {MetadataAccessor} from '@raymondfeng/pkg1'; +// @filename: monorepo/pkg2/package.json +{ + "name": "@raymondfeng/pkg2", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" +} +// @filename: monorepo/pkg3/src/index.ts +export * from './keys'; +// @filename: monorepo/pkg3/src/keys.ts +import {MetadataAccessor} from "@raymondfeng/pkg2"; + +export const ADMIN = MetadataAccessor.create('1'); +// @filename: monorepo/pkg3/tsconfig.json +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "target": "es5", + "module": "commonjs", + "strict": true, + "esModuleInterop": true, + "declaration": true + } +} +// @link: tests/cases/compiler/monorepo/pkg1 -> tests/cases/compiler/monorepo/pkg2/node_modules/@raymondfeng/pkg1 +// @link: tests/cases/compiler/monorepo/pkg2 -> tests/cases/compiler/monorepo/pkg3/node_modules/@raymondfeng/pkg2 From f18e5b2ed63a60b0b8bac88aabb224e7716e0a9a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 9 Nov 2018 17:08:17 -0800 Subject: [PATCH 2/5] Small refactorings --- src/compiler/checker.ts | 53 ++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1136e55fec364..783e7519468b9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2597,20 +2597,20 @@ namespace ts { return getMergedSymbol(symbol.parent && getLateBoundSymbol(symbol.parent)); } - function getAlternativeContainingModules(symbol: Symbol, enclosingDeclaration: Node): Symbol[] | undefined { + function getAlternativeContainingModules(symbol: Symbol, enclosingDeclaration: Node): Symbol[] { + const results: Symbol[] = []; const containingFile = getSourceFileOfNode(enclosingDeclaration); if (containingFile && containingFile.imports) { // Try to make an import using an import already in the enclosing file, if possible - let results: Symbol[] | undefined; for (const importRef of containingFile.imports) { if (nodeIsSynthesized(importRef)) continue; // Synthetic names can't be resolved by `resolveExternalModuleName` - they'll cause a debug assert if they error const resolvedModule = resolveExternalModuleName(enclosingDeclaration, importRef); if (!resolvedModule) continue; const ref = getAliasForSymbolInContainer(resolvedModule, symbol); if (!ref) continue; - results = append(results, resolvedModule); + results.push(resolvedModule); } - if (results) { + if (length(results)) { return results; } } @@ -2618,7 +2618,6 @@ namespace ts { if (links.extendedContainers) { return links.extendedContainers; } - let results: Symbol[] = []; // No results from files already being imported by this file - expand search (expensive, but not location-specific, so cached) const otherFiles = host.getSourceFiles(); for (const file of otherFiles) { @@ -2626,7 +2625,7 @@ namespace ts { const sym = getSymbolOfNode(file); const ref = getAliasForSymbolInContainer(sym, symbol); if (!ref) continue; - results = append(results, sym); + results.push(sym); } return links.extendedContainers = results; } @@ -3985,15 +3984,21 @@ namespace ts { /** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */ function getSymbolChain(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): Symbol[] | undefined { let accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & NodeBuilderFlags.UseOnlyExternalAliasing)); - + let parentSpecifiers: (string | undefined)[] | undefined; if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { // Go up and add our parent. const parents = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration); if (length(parents)) { - parents!.sort(sortByBestName); - for (const parent of parents!) { + parentSpecifiers = parents!.map(symbol => + some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol) + ? getSpecifierForModuleSymbol(symbol, context) + : undefined); + const indices = parents!.map((_, i) => i); + indices.sort(sortByBestName); + const sortedParents = indices.map(i => parents![i]); + for (const parent of sortedParents) { const parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); if (parentChain) { accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); @@ -4017,24 +4022,24 @@ namespace ts { } return [symbol]; } - } - function sortByBestName(a: Symbol, b: Symbol) { - if (some(a.declarations, hasNonGlobalAugmentationExternalModuleSymbol) && some(b.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { - const specifierA = getSpecifierForModuleSymbol(a, context); - const specifierB = getSpecifierForModuleSymbol(b, context); - if (pathIsRelative(specifierA) === pathIsRelative(specifierB)) { - // Both relative or both non-relative, sort by number of parts - return moduleSpecifiers.countPathComponents(specifierA) - moduleSpecifiers.countPathComponents(specifierB); - } - if (pathIsRelative(specifierB)) { - // A is non-relative, B is relative: prefer A - return -1; + function sortByBestName(a: number, b: number) { + const specifierA = parentSpecifiers![a]; + const specifierB = parentSpecifiers![b]; + if (specifierA && specifierB) { + if (pathIsRelative(specifierA) === pathIsRelative(specifierB)) { + // Both relative or both non-relative, sort by number of parts + return moduleSpecifiers.countPathComponents(specifierA) - moduleSpecifiers.countPathComponents(specifierB); + } + if (pathIsRelative(specifierB)) { + // A is non-relative, B is relative: prefer A + return -1; + } + // A is relative, B is non-relative: prefer B + return 1; } - // A is relative, B is non-relative: prefer B - return 1; + return 0; } - return 0; } } From a04077c6f25d838ef3762023a481b1a8b4ecc8a5 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 9 Nov 2018 17:17:25 -0800 Subject: [PATCH 3/5] Add file-by-file cacheing --- src/compiler/checker.ts | 9 +++++++-- src/compiler/types.ts | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 783e7519468b9..f6f3a26625700 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2598,8 +2598,13 @@ namespace ts { } function getAlternativeContainingModules(symbol: Symbol, enclosingDeclaration: Node): Symbol[] { - const results: Symbol[] = []; const containingFile = getSourceFileOfNode(enclosingDeclaration); + const id = "" + getNodeId(containingFile); + const links = getSymbolLinks(symbol); + if (links.extendedContainersByFile && links.extendedContainersByFile.has(id)) { + return links.extendedContainersByFile.get(id)!; + } + const results: Symbol[] = []; if (containingFile && containingFile.imports) { // Try to make an import using an import already in the enclosing file, if possible for (const importRef of containingFile.imports) { @@ -2611,10 +2616,10 @@ namespace ts { results.push(resolvedModule); } if (length(results)) { + (links.extendedContainersByFile || (links.extendedContainersByFile = createMap())).set(id, results); return results; } } - const links = getSymbolLinks(symbol); if (links.extendedContainers) { return links.extendedContainers; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 32057b8ebc370..646f3ca83f7b9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3653,6 +3653,7 @@ namespace ts { lateSymbol?: Symbol; // Late-bound symbol for a computed property specifierCache?: Map; // For symbols corresponding to external modules, a cache of incoming path -> module specifier name mappings extendedContainers?: Symbol[]; // Containers (other than the parent) which this symbol is aliased in + extendedContainersByFile?: Map; // Containers (other than the parent) which this symbol is aliased in variances?: Variance[]; // Alias symbol type argument variance cache } From c0534138e0a438676a1ccadb327118bec7c3c0e5 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 12 Nov 2018 14:21:11 -0800 Subject: [PATCH 4/5] Minor cleanups --- src/compiler/checker.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f6f3a26625700..67c129ed4a6e2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2601,10 +2601,10 @@ namespace ts { const containingFile = getSourceFileOfNode(enclosingDeclaration); const id = "" + getNodeId(containingFile); const links = getSymbolLinks(symbol); - if (links.extendedContainersByFile && links.extendedContainersByFile.has(id)) { - return links.extendedContainersByFile.get(id)!; + let results: Symbol[] | undefined; + if (links.extendedContainersByFile && (results = links.extendedContainersByFile.get(id))) { + return results; } - const results: Symbol[] = []; if (containingFile && containingFile.imports) { // Try to make an import using an import already in the enclosing file, if possible for (const importRef of containingFile.imports) { @@ -2613,11 +2613,11 @@ namespace ts { if (!resolvedModule) continue; const ref = getAliasForSymbolInContainer(resolvedModule, symbol); if (!ref) continue; - results.push(resolvedModule); + results = append(results, resolvedModule); } if (length(results)) { - (links.extendedContainersByFile || (links.extendedContainersByFile = createMap())).set(id, results); - return results; + (links.extendedContainersByFile || (links.extendedContainersByFile = createMap())).set(id, results!); + return results!; } } if (links.extendedContainers) { @@ -2630,9 +2630,9 @@ namespace ts { const sym = getSymbolOfNode(file); const ref = getAliasForSymbolInContainer(sym, symbol); if (!ref) continue; - results.push(sym); + results = append(results, sym); } - return links.extendedContainers = results; + return links.extendedContainers = results || emptyArray; } /** @@ -3989,7 +3989,7 @@ namespace ts { /** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */ function getSymbolChain(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): Symbol[] | undefined { let accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & NodeBuilderFlags.UseOnlyExternalAliasing)); - let parentSpecifiers: (string | undefined)[] | undefined; + let parentSpecifiers: (string | undefined)[]; if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { @@ -4029,14 +4029,15 @@ namespace ts { } function sortByBestName(a: number, b: number) { - const specifierA = parentSpecifiers![a]; - const specifierB = parentSpecifiers![b]; + const specifierA = parentSpecifiers[a]; + const specifierB = parentSpecifiers[b]; if (specifierA && specifierB) { - if (pathIsRelative(specifierA) === pathIsRelative(specifierB)) { + const isBRelative = pathIsRelative(specifierB); + if (pathIsRelative(specifierA) === isBRelative) { // Both relative or both non-relative, sort by number of parts return moduleSpecifiers.countPathComponents(specifierA) - moduleSpecifiers.countPathComponents(specifierB); } - if (pathIsRelative(specifierB)) { + if (isBRelative) { // A is non-relative, B is relative: prefer A return -1; } From a8dd3a610085b29ead94d4b115e79f7e2c6681fa Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 13 Nov 2018 13:40:22 -0800 Subject: [PATCH 5/5] Adjust error message --- src/compiler/diagnosticMessages.json | 2 +- src/compiler/transformers/declarations.ts | 2 +- .../declarationEmitCommonJsModuleReferencedType.errors.txt | 4 ++-- .../declarationEmitReexportedSymlinkReference3.errors.txt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0aa0283476196..f40c6e7be5b83 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2525,7 +2525,7 @@ "category": "Error", "code": 2741 }, - "The inferred type of '{0}' requires a reference to a module at '{1}' to name, which would likely break on type redistribution. A type annotation is necessary.": { + "The inferred type of '{0}' cannot be named without a reference to '{1}'. This is likely not portable. A type annotation is necessary.": { "category": "Error", "code": 2742 }, diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 7fb75b3d18706..973b9db618ee2 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -156,7 +156,7 @@ namespace ts { function reportLikelyUnsafeImportRequiredError(specifier: string) { if (errorNameNode) { - context.addDiagnostic(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_requires_a_reference_to_a_module_at_1_to_name_which_would_likely_break_on_type_redistribution_A_type_annotation_is_necessary, + context.addDiagnostic(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, declarationNameToString(errorNameNode), specifier)); } diff --git a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt index 546736a76a9b7..d2dcd236ad7bb 100644 --- a/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt +++ b/tests/baselines/reference/declarationEmitCommonJsModuleReferencedType.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/r/entry.ts(3,14): error TS2742: The inferred type of 'x' requires a reference to a module at 'foo/node_modules/nested' to name, which would likely break on type redistribution. A type annotation is necessary. +tests/cases/compiler/r/entry.ts(3,14): error TS2742: The inferred type of 'x' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. ==== tests/cases/compiler/r/node_modules/foo/node_modules/nested/index.d.ts (0 errors) ==== @@ -23,6 +23,6 @@ tests/cases/compiler/r/entry.ts(3,14): error TS2742: The inferred type of 'x' re import { bar } from "root"; export const x = foo(); ~ -!!! error TS2742: The inferred type of 'x' requires a reference to a module at 'foo/node_modules/nested' to name, which would likely break on type redistribution. A type annotation is necessary. +!!! error TS2742: The inferred type of 'x' cannot be named without a reference to 'foo/node_modules/nested'. This is likely not portable. A type annotation is necessary. export const y = bar(); \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt index 5fc828b693e2f..1981ce63c9282 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/monorepo/pkg3/src/keys.ts(3,14): error TS2742: The inferred type of 'ADMIN' requires a reference to a module at '../../pkg2/node_modules/@raymondfeng/pkg1/dist' to name, which would likely break on type redistribution. A type annotation is necessary. +tests/cases/compiler/monorepo/pkg3/src/keys.ts(3,14): error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. ==== tests/cases/compiler/monorepo/pkg3/tsconfig.json (0 errors) ==== @@ -57,4 +57,4 @@ tests/cases/compiler/monorepo/pkg3/src/keys.ts(3,14): error TS2742: The inferred export const ADMIN = MetadataAccessor.create('1'); ~~~~~ -!!! error TS2742: The inferred type of 'ADMIN' requires a reference to a module at '../../pkg2/node_modules/@raymondfeng/pkg1/dist' to name, which would likely break on type redistribution. A type annotation is necessary. \ No newline at end of file +!!! error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. \ No newline at end of file