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

alias imports of namespaced types are failing when using ts-loader with fork-ts-checker-webpack-plugin #644

Closed
alfrescian opened this issue Sep 25, 2017 · 5 comments

Comments

@alfrescian
Copy link

I've created a simple example repository to reproduce the issue:
https://github.com/alfrescian/fork-ts-checker-issue

I've an index.ts that does the following alias import of a type defined in a namespace:
import foo = myNamespace.foo;
const myFoo: foo = {foo: 'foo'};

when using ts-loader with fork-ts-checker-webpack-plugin then the output is (run npm run fork and check dist/index.js):
var foo = myNamespace.foo;
var myFoo = { foo: 'check' };

JS runtime will complain about myNamespace is undefined.

when using ts-loader without fork-ts-checker-webpack-plugin then the output is (run npm run no-fork and check dist/index.no-fork.js):
var myFoo = { foo: 'check' };

we are heavily using namespaces & these kinds of alias imports in our project & that currently blocks us using fork-ts-checker-webpack-plugin.

it does not make any difference if an ambient or non-ambient namespace is used. (see index.ts in my example)

@johnnyreilly
Copy link
Member

I think this may be a fork-ts-checker-webpack-plugin issue rather than a ts-loader one. Do you want to raise your issue there?

@alfrescian
Copy link
Author

yeah - wasn't sure about it and don't want to cross post. I'll open an issue there

@johnnyreilly
Copy link
Member

It's worth saying that I believe namespaces are not advised to be used with modules BTW. I don't have the relevant link but I'm pretty sure that's the case

@alfrescian
Copy link
Author

alfrescian commented Sep 25, 2017

hm - would be interesting to get a link for that.
The alias import we're doing is e.g. mentioned here (scroll down to Aliases)
http://www.typescriptlang.org/docs/handbook/namespaces.html

@johnnyreilly
Copy link
Member

Yeah - I checked there too. Interestingly I believe the context there is internal modules. Could be worth looking on stackoverflow - I believe one of the core team answers and question about this. Or something like that

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