mockdeep / typewiz

Automatically discover and add missing types in your TypeScript code
https://medium.com/@urish/manual-typing-is-no-fun-introducing-typewiz-58e3e8813f4c
1.1k stars 46 forks source link

Avoid emitting 'Function' #20

Closed DanielRosenwasser closed 6 years ago

DanielRosenwasser commented 6 years ago

While 'Function' is very general, it's problematic in some ways because it's not assignable back to types with more general call signatures like (...args: any[]) => any.

You can probably take some inspiration from how dts-gen determines arity for function to improve things here.

urish commented 6 years ago

That's a good point, thank you Daniel!

Another thought I had - perhaps creating a Proxy object and wrapping the function with this Proxy will allow to actually detect the argument types in runtime?

The dts-gen solution sounds easier to start with though.

kaminskypavel commented 6 years ago

@DanielRosenwasser great suggestion, i'll have a stab at it

DanielRosenwasser commented 6 years ago

Just as a heads up, dts-gen uses a package called dts-dom which is also another handy utility you can use for building up declarations. 😃