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

Typewiz error on overloaded functions in this simple create-react-app repro #85

Closed zxti closed 5 years ago

zxti commented 5 years ago

I've gotten a taste of typewiz by running some of my codebase in node, and it's awesome! But now when I turned to run it over the create-react-app-based codebase, I'm seeing errors when encountering exported function overloads, for some reason (which I didn't see occur in typewiz-node, oddly).

I've created a repro of this, which requires the following two repos:

To get started, clone both repos, then run:

cd react-scripts-ts
yarn link
yarn install
cd ../cra-typewiz-example
yarn link react-scripts-ts
yarn install
yarn start

When the dev server starts, it spits out the error:

./src/App.tsx 6:16
Module parse failed: Identifier 'foo' has already been declared (6:16)
You may need an appropriate loader to handle this file type.
| import logo from "./logo.svg";
| export function foo(x) { }
> export function foo(x) { }
| export function foo(x) { }

Any ideas around this? I hope my creating these repos helps!

urish commented 5 years ago

Thanks for creating a reproduction repo, I'm going to look into this

urish commented 5 years ago

Reproduced with the following test case (in instrument.spec.ts):

    it('should not instrument a function declaration that has no a body', () => {
        // See issue #85 for details
        const input = `function foo(n: number): void;`;
        expect(instrument(input, 'test.ts')).toContain(
            astPrettyPrint('function foo(n: number): void;'),
        );
    });
urish commented 5 years ago

Fix released as typewiz 1.2.3

zxti commented 5 years ago

Fast work! Works perfectly now. Can't wait to get this going again. Thank you!