Add test that fails to emit declarations correctly

This commit is contained in:
Sheetal Nandi
2019-09-20 14:11:10 -07:00
parent b76277092c
commit d6a3a944d7
3 changed files with 98 additions and 0 deletions
+1
View File
@@ -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",
@@ -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<Payload> {
type: string;
payload: Payload;
}
export declare type ActionCreator<Payload> = {
type: string;
(payload: Payload): Action<Payload>;
}
export interface ActionCreatorFactory {
<Payload = void>(type: string): ActionCreator<Payload>;
}
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"]
});
});
}
@@ -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 });