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

Can't import class type from default export object #35308

Closed
joaovieira opened this issue Nov 23, 2019 · 2 comments
Closed

Can't import class type from default export object #35308

joaovieira opened this issue Nov 23, 2019 · 2 comments

Comments

@joaovieira
Copy link

TypeScript Version: 3.8.0-dev.20191122

Search Terms: namespace default exports

Code

// index.ts
class Bar {}
export default { Bar };
// generated declaration index.d.ts
declare const _default: {
    Bar: {
        new (): {};
    };
};
export default _default;
// index.test-d.ts
import foo from '.';

const test: foo.Bar = new foo.Bar();

Expected behavior:
foo.Bar to reference the Bar class type and compile correctly.

Actual behavior:

index.test-d.ts:3:13 - error TS2503: Cannot find namespace 'foo'.

3 const test: foo.Bar = new foo.Bar();
              ~~~

Related issues: sindresorhus/ky#206

@nmain
Copy link

nmain commented Nov 25, 2019

Dot notation in a type expression is namespace syntax, not member access.
foo is not a type, it's just a value.
There are a few ways to refer to the type of the expression new foo.Bar() in this context; one straightforward way is InstanceType<typeof foo.Bar>.

Questions that are not bug reports or feature requests should go to Stack Overflow.

@joaovieira
Copy link
Author

@nmain did not know about those utility types. That does it. Thanks!

It could be considered a bug if you're expecting the compiler to generate a namespace. But that makes sense. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants