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

AsyncHook in types #159

Open
watjurk opened this issue Apr 24, 2021 · 6 comments
Open

AsyncHook in types #159

watjurk opened this issue Apr 24, 2021 · 6 comments

Comments

@watjurk
Copy link

watjurk commented Apr 24, 2021

AsyncHook is declared in types but not exported by lib, this leads to types errors when trying to instantiate new AsyncHook.

error TypeError: tapable.AsyncHook is not a constructor

I would propose remove AsyncHook from tapable.d.ts because it's misleading.
Thanks!

@alexander-akait
Copy link
Member

TypeError is not related to types, you have wrong code

@watjurk
Copy link
Author

watjurk commented Apr 26, 2021

I believe that's not true.
AsyncHook is declared by tapable.d.ts and when compiling code like this:

import { AsyncHook } from "tapable";

const someHook = new AsyncHook();

Typescript throws no error, but at runtime module tapable does not export AsyncHook and we get TypeError.
We are declaring AsyncHook in the types so typescript compiles no problem but when we try to run it there is no AsyncHook exported by tapable. Do you see the problem now?

@alexander-akait
Copy link
Member

There is not AsyncHook export, check it https://github.com/webpack/tapable/blob/master/tapable.d.ts

@watjurk
Copy link
Author

watjurk commented Apr 26, 2021

Oh you are right. There seams to be some "feature" of typescript which automatically exports declared stuff. The only "workaroud" I've found is to declare the "private" types in separate file and then import them in tapable.d.ts.

I think that this should be done in this case because importing not existing class and not getting error from typescript, and getting an TypeError on runtime is very confusing.

@alexander-akait
Copy link
Member

Why you need AsyncHook?

@watjurk
Copy link
Author

watjurk commented Apr 26, 2021

No I don't need it, I meant that the fact that I'm able to import it (at least it types) from tapable is very confusing.

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