Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

[flow] declare function does not recognize bounded polymorphic types #445

Closed
rattrayalex opened this issue Mar 18, 2017 · 4 comments
Closed

Comments

@rattrayalex
Copy link
Contributor

In the course of #444 , I noticed that

    it("declared function type parameter bounds", () => {
      verifyAndAssertMessages(
        unpad(`
          import type Foo from 'foo';
          declare function foo<T: Foo>(a: T): T;
          foo(1);
        `),
        { "no-unused-vars": 1, "no-undef": 1 },
        []
      );
    });

results in

[
   {
      "ruleId":"no-unused-vars",
      "severity":1,
      "message":"'Foo' is defined but never used.",
      "line":1,
      "column":13,
      "nodeType":"Identifier",
      "source":"import type Foo from 'foo';"
   }
]

and

    it("declared class type parameter bounds", () => {
      verifyAndAssertMessages(
        unpad(`
          import type Foo from 'foo';
          declare class C<T: Foo> {
            x: T
          };
          new C();
        `),
        { "no-unused-vars": 1, "no-undef": 1 },
        []
      );
    });

results in

[
   {
      "ruleId":"no-unused-vars",
      "severity":1,
      "message":"'Foo' is defined but never used.",
      "line":1,
      "column":13,
      "nodeType":"Identifier",
      "source":"import type Foo from 'foo';"
   },
   {
      "ruleId":"no-unused-vars",
      "severity":1,
      "message":"'T' is defined but never used.",
      "line":2,
      "column":17,
      "nodeType":"Identifier",
      "source":"declare class C<T: Foo> {"
   }
]

I don't use Flow much, so I'm not encountering this in the wild, but trying the above at https://flowtype.org/try/ appears to indicate that the code is semantically correct.

@rattrayalex rattrayalex changed the title [flow] declare function does not recognized bounded polymorphic types [flow] declare function does not recognize bounded polymorphic types Mar 23, 2017
@zertosh
Copy link
Member

zertosh commented Mar 27, 2017

@rattrayalex #459 now fixes this, but I need to split up that PR

@rattrayalex
Copy link
Contributor Author

Nice!

@pronebird
Copy link

pronebird commented Jun 30, 2017

I have a similar case:

declare class ClipboardData {
  setData(type: string, data: string): void;
  getData(type: string): string;
}

declare class ClipboardEvent extends Event {
  clipboardData: ClipboardData;
}

Output:

'ClipboardData' is defined but never used.

@kaicataldo
Copy link
Member

Thank you for the issue. Now that @babel/eslint-parser has been released, we are making this repository read-only. If this is a change you would still like to advocate for, please reopen this in the babel/babel monorepo.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants