webpack / tapable

Just a little module for plugins.
MIT License
3.71k stars 393 forks source link

TS Error #169

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hello. First of all, I just wanted to say this is a nice library. Unfortunately sadly, it was wrongly typed.

I was testing out this library (with TS) and it produces the following error:

Argument of type '[string, string, string]' is not assignable to parameter of type 'readonly string[] & { 0: string; length: 1; }'.
  Type '[string, string, string]' is not assignable to type '{ 0: string; length: 1; }'.
    Types of property 'length' are incompatible.
      Type '3' is not assignable to type '1'

Code:

const hook = new SyncBailHook(['arg1', 'arg2', 'arg3']);
ghost commented 2 years ago

https://github.com/webpack/tapable/blob/a0a7b26224557bd8bb09b97e0126b7dbda9f8e6a/tapable.d.ts#L59 Maybe adding a string[] should help here? I'm not sure how it works internally but according to the example, it should work.

All Hook constructors take one optional argument, which is a list of argument names as strings.

ghost commented 2 years ago
- constructor(args?: ArgumentNames<AsArray<T>>, name?: string); 
+ constructor(args?: ArgumentNames<AsArray<T>> | string[], name?: string); 
ghost commented 2 years ago

Actually, I think in this context (and some other context), ArgumentNames<AsArray<T>> is not needed. Instead, use string[]. I'll submit a PR when I have time.