diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 5f8b3e87ec9..76bda690009 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -109,6 +109,7 @@ "unittests/tsbuild/transitiveReferences.ts", "unittests/tsbuild/watchEnvironment.ts", "unittests/tsbuild/watchMode.ts", + "unittests/tsc/declarationEmit.ts", "unittests/tscWatch/consoleClearing.ts", "unittests/tscWatch/emit.ts", "unittests/tscWatch/emitAndErrorUpdates.ts", diff --git a/src/testRunner/unittests/tsc/declarationEmit.ts b/src/testRunner/unittests/tsc/declarationEmit.ts new file mode 100644 index 00000000000..4ec2819a734 --- /dev/null +++ b/src/testRunner/unittests/tsc/declarationEmit.ts @@ -0,0 +1,73 @@ +namespace ts { + describe("unittests:: tsc:: declarationEmit::", () => { + verifyTsc({ + scenario: "declarationEmit", + subScenario: "when same version is referenced through source and another symlinked package", + fs: () => { + const fsaPackageJson = utils.dedent` + { + "name": "typescript-fsa", + "version": "3.0.0-beta-2" + }`; + const fsaIndex = utils.dedent` + export interface Action { + type: string; + payload: Payload; + } + export declare type ActionCreator = { + type: string; + (payload: Payload): Action; + } + export interface ActionCreatorFactory { + (type: string): ActionCreator; + } + export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; + export default actionCreatorFactory;`; + return loadProjectFromFiles({ + "/plugin-two/index.d.ts": utils.dedent` + declare const _default: { + features: { + featureOne: { + actions: { + featureOne: { + (payload: { + name: string; + order: number; + }, meta?: { + [key: string]: any; + }): import("typescript-fsa").Action<{ + name: string; + order: number; + }>; + }; + }; + path: string; + }; + }; + }; + export default _default;`, + "/plugin-two/node_modules/typescript-fsa/package.json": fsaPackageJson, + "/plugin-two/node_modules/typescript-fsa/index.d.ts": fsaIndex, + "/plugin-one/tsconfig.json": utils.dedent` + { + "compilerOptions": { + "target": "es5", + "declaration": true, + }, + }`, + "/plugin-one/index.ts": utils.dedent` + import pluginTwo from "plugin-two"; // include this to add reference to symlink`, + "/plugin-one/action.ts": utils.dedent` + import { actionCreatorFactory } from "typescript-fsa"; // Include version of shared lib + const action = actionCreatorFactory("somekey"); + const featureOne = action<{ route: string }>("feature-one"); + export const actions = { featureOne };`, + "/plugin-one/node_modules/typescript-fsa/package.json": fsaPackageJson, + "/plugin-one/node_modules/typescript-fsa/index.d.ts": fsaIndex, + "/plugin-one/node_modules/plugin-two": new vfs.Symlink("/plugin-two"), + }); + }, + commandLineArgs: ["-p", "plugin-one"] + }); + }); +} diff --git a/tests/baselines/reference/tsc/declarationEmit/initial-build/when-same-version-is-referenced-through-source-and-another-symlinked-package.js b/tests/baselines/reference/tsc/declarationEmit/initial-build/when-same-version-is-referenced-through-source-and-another-symlinked-package.js new file mode 100644 index 00000000000..c7ccb8014c3 --- /dev/null +++ b/tests/baselines/reference/tsc/declarationEmit/initial-build/when-same-version-is-referenced-through-source-and-another-symlinked-package.js @@ -0,0 +1,24 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc -p plugin-one +plugin-one/action.ts(4,14): error TS2742: The inferred type of 'actions' cannot be named without a reference to 'plugin-two/node_modules/typescript-fsa'. This is likely not portable. A type annotation is necessary. +exitCode:: 1 + + +//// [/plugin-one/action.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var typescript_fsa_1 = require("typescript-fsa"); // Include version of shared lib +var action = typescript_fsa_1.actionCreatorFactory("somekey"); +var featureOne = action("feature-one"); +exports.actions = { featureOne: featureOne }; + + +//// [/plugin-one/index.d.ts] +export {}; + + +//// [/plugin-one/index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + +