tapable
tapable copied to clipboard
AsyncHook in types
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!
TypeError
is not related to types, you have wrong code
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?
There is not AsyncHook
export, check it https://github.com/webpack/tapable/blob/master/tapable.d.ts
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.
Why you need AsyncHook
?
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.