Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--moduleResolution minimal #50153

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test a non-portable declaration emit issue
  • Loading branch information
andrewbranch committed Sep 26, 2022
commit 6242ee31a7cf36ae2ff29024d0145352220a6c45
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/main.ts(1,14): error TS2742: The inferred type of 'boom' cannot be named without a reference to './node_modules/foo/module.js'. This is likely not portable. A type annotation is necessary.


==== /node_modules/foo/module.d.ts (0 errors) ====
export declare class SomeExportedClass {
private foo: any;
}

declare global {
function returnsPrivateClassOhNo(): SomeExportedClass;
}

==== /main.ts (1 errors) ====
export const boom = returnsPrivateClassOhNo();
~~~~
!!! error TS2742: The inferred type of 'boom' cannot be named without a reference to './node_modules/foo/module.js'. This is likely not portable. A type annotation is necessary.

20 changes: 20 additions & 0 deletions tests/baselines/reference/minimal_nodeModules_declarationEmit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//// [tests/cases/conformance/moduleResolution/minimal_nodeModules_declarationEmit.ts] ////

//// [module.d.ts]
export declare class SomeExportedClass {
private foo: any;
}

declare global {
function returnsPrivateClassOhNo(): SomeExportedClass;
}

//// [main.ts]
export const boom = returnsPrivateClassOhNo();


//// [main.js]
"use strict";
exports.__esModule = true;
exports.boom = void 0;
exports.boom = returnsPrivateClassOhNo();
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
=== /node_modules/foo/module.d.ts ===
export declare class SomeExportedClass {
>SomeExportedClass : Symbol(SomeExportedClass, Decl(module.d.ts, 0, 0))

private foo: any;
>foo : Symbol(SomeExportedClass.foo, Decl(module.d.ts, 0, 40))
}

declare global {
>global : Symbol(global, Decl(module.d.ts, 2, 1))

function returnsPrivateClassOhNo(): SomeExportedClass;
>returnsPrivateClassOhNo : Symbol(returnsPrivateClassOhNo, Decl(module.d.ts, 4, 16))
>SomeExportedClass : Symbol(SomeExportedClass, Decl(module.d.ts, 0, 0))
}

=== /main.ts ===
export const boom = returnsPrivateClassOhNo();
>boom : Symbol(boom, Decl(main.ts, 0, 12))
>returnsPrivateClassOhNo : Symbol(returnsPrivateClassOhNo, Decl(module.d.ts, 4, 16))

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
=== /node_modules/foo/module.d.ts ===
export declare class SomeExportedClass {
>SomeExportedClass : SomeExportedClass

private foo: any;
>foo : any
}

declare global {
>global : typeof global

function returnsPrivateClassOhNo(): SomeExportedClass;
>returnsPrivateClassOhNo : () => SomeExportedClass
}

=== /main.ts ===
export const boom = returnsPrivateClassOhNo();
>boom : import("/node_modules/foo/module").SomeExportedClass
>returnsPrivateClassOhNo() : import("/node_modules/foo/module").SomeExportedClass
>returnsPrivateClassOhNo : () => import("/node_modules/foo/module").SomeExportedClass

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @moduleResolution: minimal
// @declaration: true

// @Filename: /node_modules/foo/module.d.ts
export declare class SomeExportedClass {
private foo: any;
}

declare global {
function returnsPrivateClassOhNo(): SomeExportedClass;
}

// @Filename: /main.ts
export const boom = returnsPrivateClassOhNo();