Skip to content

Commit d6a3a94

Browse files
committed
Add test that fails to emit declarations correctly
1 parent b762770 commit d6a3a94

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"unittests/tsbuild/transitiveReferences.ts",
110110
"unittests/tsbuild/watchEnvironment.ts",
111111
"unittests/tsbuild/watchMode.ts",
112+
"unittests/tsc/declarationEmit.ts",
112113
"unittests/tscWatch/consoleClearing.ts",
113114
"unittests/tscWatch/emit.ts",
114115
"unittests/tscWatch/emitAndErrorUpdates.ts",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace ts {
2+
describe("unittests:: tsc:: declarationEmit::", () => {
3+
verifyTsc({
4+
scenario: "declarationEmit",
5+
subScenario: "when same version is referenced through source and another symlinked package",
6+
fs: () => {
7+
const fsaPackageJson = utils.dedent`
8+
{
9+
"name": "typescript-fsa",
10+
"version": "3.0.0-beta-2"
11+
}`;
12+
const fsaIndex = utils.dedent`
13+
export interface Action<Payload> {
14+
type: string;
15+
payload: Payload;
16+
}
17+
export declare type ActionCreator<Payload> = {
18+
type: string;
19+
(payload: Payload): Action<Payload>;
20+
}
21+
export interface ActionCreatorFactory {
22+
<Payload = void>(type: string): ActionCreator<Payload>;
23+
}
24+
export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory;
25+
export default actionCreatorFactory;`;
26+
return loadProjectFromFiles({
27+
"/plugin-two/index.d.ts": utils.dedent`
28+
declare const _default: {
29+
features: {
30+
featureOne: {
31+
actions: {
32+
featureOne: {
33+
(payload: {
34+
name: string;
35+
order: number;
36+
}, meta?: {
37+
[key: string]: any;
38+
}): import("typescript-fsa").Action<{
39+
name: string;
40+
order: number;
41+
}>;
42+
};
43+
};
44+
path: string;
45+
};
46+
};
47+
};
48+
export default _default;`,
49+
"/plugin-two/node_modules/typescript-fsa/package.json": fsaPackageJson,
50+
"/plugin-two/node_modules/typescript-fsa/index.d.ts": fsaIndex,
51+
"/plugin-one/tsconfig.json": utils.dedent`
52+
{
53+
"compilerOptions": {
54+
"target": "es5",
55+
"declaration": true,
56+
},
57+
}`,
58+
"/plugin-one/index.ts": utils.dedent`
59+
import pluginTwo from "plugin-two"; // include this to add reference to symlink`,
60+
"/plugin-one/action.ts": utils.dedent`
61+
import { actionCreatorFactory } from "typescript-fsa"; // Include version of shared lib
62+
const action = actionCreatorFactory("somekey");
63+
const featureOne = action<{ route: string }>("feature-one");
64+
export const actions = { featureOne };`,
65+
"/plugin-one/node_modules/typescript-fsa/package.json": fsaPackageJson,
66+
"/plugin-one/node_modules/typescript-fsa/index.d.ts": fsaIndex,
67+
"/plugin-one/node_modules/plugin-two": new vfs.Symlink("/plugin-two"),
68+
});
69+
},
70+
commandLineArgs: ["-p", "plugin-one"]
71+
});
72+
});
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc -p plugin-one
3+
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.
4+
exitCode:: 1
5+
6+
7+
//// [/plugin-one/action.js]
8+
"use strict";
9+
Object.defineProperty(exports, "__esModule", { value: true });
10+
var typescript_fsa_1 = require("typescript-fsa"); // Include version of shared lib
11+
var action = typescript_fsa_1.actionCreatorFactory("somekey");
12+
var featureOne = action("feature-one");
13+
exports.actions = { featureOne: featureOne };
14+
15+
16+
//// [/plugin-one/index.d.ts]
17+
export {};
18+
19+
20+
//// [/plugin-one/index.js]
21+
"use strict";
22+
Object.defineProperty(exports, "__esModule", { value: true });
23+
24+

0 commit comments

Comments
 (0)