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

fix #20: Avoid emitting 'Function' #21

Closed kaminskypavel closed 6 years ago

kaminskypavel commented 6 years ago

fixing #20 for the following cases

fn = () => a fn = (a = 5) => a fn = ({a}) => a fn = ([a]) => a fn = (...args) => args[0]

coveralls commented 6 years ago

Coverage Status

Coverage increased (+1.7%) to 85.017% when pulling ae01c0f0acaaab1db34f7267017babb3671ebbfc on kaminskypavel:master into 4f450afcd7cae8c3ed31a77e0b282927c1f8c84f on urish:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+1.7%) to 85.017% when pulling ae01c0f0acaaab1db34f7267017babb3671ebbfc on kaminskypavel:master into 4f450afcd7cae8c3ed31a77e0b282927c1f8c84f on urish:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+1.5%) to 84.88% when pulling bff230f47adf7930e95166a3c3157f0e6a7fe4a2 on kaminskypavel:master into c413b8a8e0b89113c457f11bc7bcedc5c1f43782 on urish:master.

urish commented 6 years ago

Thanks!

Seems to be failing for standard (non-arrow) functions with zero arguments. Here is an example test case that fails:

it.only('should return "() => any" for functions without arguments', () => {
  expect(
    $_$twiz.typeName(function() {
      return new Date(0);
    }),
  ).toBe('() => any');
});

This will return (0: any) => any instead of the expected () => any).

A few more cases that produce invalid code:

([{a}]) => 0 results in ({a}Array: any) => any ({a:b}) => 0 results in (a: bObject: {a: b: any}) => any ({a: [b, c]}) => 0 results in ({​​a: bArray: any,c]​​ }: any) => any (a = Math.max(0, 2)) => 0 results in (a: any,2: any)‌⁠ => any

kaminskypavel commented 6 years ago

@urish super interesting that it would pass the test with the suite, but fail with it.only. anyhow, solved.