diff --git a/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.errors.txt b/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.errors.txt new file mode 100644 index 00000000000..e4500e1fe5d --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.errors.txt @@ -0,0 +1,27 @@ +main.ts(8,11): error TS4053: Return type of public method from exported class has or is using name 'Base' from external module "lib" but cannot be named. + + +==== lib.ts (0 errors) ==== + interface Base { } + + export type ExportBase = Base; + +==== main.ts (1 errors) ==== + import type { ExportBase } from './lib.js' + + interface Clonable { + clone(): Clonable + } + + export default class C { + async method(res: Clonable<{ key: ExportBase }>) { + ~~~~~~ +!!! error TS4053: Return type of public method from exported class has or is using name 'Base' from external module "lib" but cannot be named. + if (Math.random() > 0.5) { + res.clone(); + } else { + return res.clone(); + } + }; + } + \ No newline at end of file diff --git a/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.js b/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.js new file mode 100644 index 00000000000..db75118a164 --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.js @@ -0,0 +1,59 @@ +//// [tests/cases/compiler/declarationEmitTypeAliasCannotBeNamed.ts] //// + +//// [lib.ts] +interface Base { } + +export type ExportBase = Base; + +//// [main.ts] +import type { ExportBase } from './lib.js' + +interface Clonable { + clone(): Clonable +} + +export default class C { + async method(res: Clonable<{ key: ExportBase }>) { + if (Math.random() > 0.5) { + res.clone(); + } else { + return res.clone(); + } + }; +} + + +//// [lib.js] +export {}; +//// [main.js] +export default class C { + async method(res) { + if (Math.random() > 0.5) { + res.clone(); + } + else { + return res.clone(); + } + } + ; +} + + +//// [lib.d.ts] +interface Base { +} +export type ExportBase = Base; +export {}; +//// [main.d.ts] +import type { ExportBase } from './lib.js'; +interface Clonable { + clone(): Clonable; +} +export default class C { + method(res: Clonable<{ + key: ExportBase; + }>): Promise | undefined>; +} +export {}; diff --git a/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.symbols b/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.symbols new file mode 100644 index 00000000000..cd72565ee8c --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.symbols @@ -0,0 +1,53 @@ +//// [tests/cases/compiler/declarationEmitTypeAliasCannotBeNamed.ts] //// + +=== lib.ts === +interface Base { } +>Base : Symbol(Base, Decl(lib.ts, 0, 0)) + +export type ExportBase = Base; +>ExportBase : Symbol(ExportBase, Decl(lib.ts, 0, 18)) +>Base : Symbol(Base, Decl(lib.ts, 0, 0)) + +=== main.ts === +import type { ExportBase } from './lib.js' +>ExportBase : Symbol(ExportBase, Decl(main.ts, 0, 13)) + +interface Clonable { +>Clonable : Symbol(Clonable, Decl(main.ts, 0, 42)) +>T : Symbol(T, Decl(main.ts, 2, 19)) + + clone(): Clonable +>clone : Symbol(Clonable.clone, Decl(main.ts, 2, 23)) +>Clonable : Symbol(Clonable, Decl(main.ts, 0, 42)) +>T : Symbol(T, Decl(main.ts, 2, 19)) +} + +export default class C { +>C : Symbol(C, Decl(main.ts, 4, 1)) + + async method(res: Clonable<{ key: ExportBase }>) { +>method : Symbol(C.method, Decl(main.ts, 6, 24)) +>res : Symbol(res, Decl(main.ts, 7, 17)) +>Clonable : Symbol(Clonable, Decl(main.ts, 0, 42)) +>key : Symbol(key, Decl(main.ts, 7, 32)) +>ExportBase : Symbol(ExportBase, Decl(main.ts, 0, 13)) + + if (Math.random() > 0.5) { +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2025.float16.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + res.clone(); +>res.clone : Symbol(Clonable.clone, Decl(main.ts, 2, 23)) +>res : Symbol(res, Decl(main.ts, 7, 17)) +>clone : Symbol(Clonable.clone, Decl(main.ts, 2, 23)) + + } else { + return res.clone(); +>res.clone : Symbol(Clonable.clone, Decl(main.ts, 2, 23)) +>res : Symbol(res, Decl(main.ts, 7, 17)) +>clone : Symbol(Clonable.clone, Decl(main.ts, 2, 23)) + } + }; +} + diff --git a/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.types b/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.types new file mode 100644 index 00000000000..e4420339ac5 --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitTypeAliasCannotBeNamed.types @@ -0,0 +1,49 @@ +//// [tests/cases/compiler/declarationEmitTypeAliasCannotBeNamed.ts] //// + +=== lib.ts === +interface Base { } + +export type ExportBase = Base; +>ExportBase : Base + +=== main.ts === +import type { ExportBase } from './lib.js' +>ExportBase : Base + +interface Clonable { + clone(): Clonable +>clone : () => Clonable +} + +export default class C { +>C : C + + async method(res: Clonable<{ key: ExportBase }>) { +>method : (res: Clonable<{ key: Base; }>) => Promise | undefined> +>res : Clonable<{ key: Base; }> +>key : Base + + if (Math.random() > 0.5) { +>Math.random() > 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>0.5 : 0.5 + + res.clone(); +>res.clone() : Clonable<{ key: Base; }> +>res.clone : () => Clonable<{ key: Base; }> +>res : Clonable<{ key: Base; }> +>clone : () => Clonable<{ key: Base; }> + + } else { + return res.clone(); +>res.clone() : Clonable<{ key: Base; }> +>res.clone : () => Clonable<{ key: Base; }> +>res : Clonable<{ key: Base; }> +>clone : () => Clonable<{ key: Base; }> + } + }; +} + diff --git a/testdata/tests/cases/compiler/declarationEmitTypeAliasCannotBeNamed.ts b/testdata/tests/cases/compiler/declarationEmitTypeAliasCannotBeNamed.ts new file mode 100644 index 00000000000..5d2e2013ca7 --- /dev/null +++ b/testdata/tests/cases/compiler/declarationEmitTypeAliasCannotBeNamed.ts @@ -0,0 +1,22 @@ +// @declaration: true +// @filename: lib.ts +interface Base { } + +export type ExportBase = Base; + +// @filename: main.ts +import type { ExportBase } from './lib.js' + +interface Clonable { + clone(): Clonable +} + +export default class C { + async method(res: Clonable<{ key: ExportBase }>) { + if (Math.random() > 0.5) { + res.clone(); + } else { + return res.clone(); + } + }; +}