Skip to content

Error messages are vague when types have the same name #1419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanielRosenwasser opened this issue Dec 9, 2014 · 8 comments
Closed

Error messages are vague when types have the same name #1419

DanielRosenwasser opened this issue Dec 9, 2014 · 8 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@DanielRosenwasser
Copy link
Member

Consider the following:

module ts {
    export interface Node {
        kind: SyntaxKind;
        pos: number;
        end: number;
    }
}

function f(n: Node) {
    ts.forEachChild(n, () => { /* ... */ });
}

The subtlety is that the user meant to declare ts.Node as the type of n.

Here you'll get the error on n within the forEachChild call, with the message

TS2345 Argument of type 'Node' is not assignable to parameter of type 'Node'.

which is unhelpful because it makes the user feel like they've completely lost their mind.

We should use a qualified name in such cases.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Dec 9, 2014
@mhegazy mhegazy added this to the Community milestone Dec 9, 2014
@NoelAbrahams
Copy link

which is unhelpful because it makes the user feel like they've completely lost their mind.

true 😃

@DanielRosenwasser
Copy link
Member Author

It reminds me of this Steve Yegge post from way back.

There's nothing more fun than having your compiler tell you: "Error: expected type (int, int, int) but got type (int, int, int)". Sheesh.

You might note the irony of the section that appears in. 😄

@chrisbubernak
Copy link
Contributor

Did anyone ever end up working on this? I took a look at it this morning and it doesn't seem too bad. I'll send out a PR when I get a chance to finish it up & test.

@DickvdBrink
Copy link
Contributor

@chrisbubernak, I worked on this a few weeks back, was a pretty minor change but it ended up breaking some other things (when I looked at the baselines, I believe it was something with the require paths now gone from the baseline), and I never had the time to actually look at it more. :(

@NoelAbrahams
Copy link

@DanielRosenwasser /@chrisbubernak,

I ran into this gem today using 1.4:

Class 'Baz' incorrectly implements interface 'BazInternal'.
  Types of property 'equals' are incompatible.
    Type '(other: Baz) => boolean' is not assignable to type '(other: Baz) => boolean'.
      Types of parameters 'other' and 'other' are incompatible.
        Type 'Baz' is not assignable to type 'Baz'.
          Types of property 'bar' are incompatible.
            Type '(handler: (event: DragEvent) => void) => void' is not assignable to type '(handler: (event: DragEvent) => void) => void'.
              Types of parameters 'handler' and 'handler' are incompatible.
                Type '(event: DragEvent) => void' is not assignable to type '(event: DragEvent) => void'.
                  Types of parameters 'event' and 'event' are incompatible.
                    Type 'DragEvent' is not assignable to type 'DragEvent'.
                      Property 'foo' is missing in type 'DragEvent'.

I mean Types of parameters 'other' and 'other' are incompatible might be a candidate for the error messages hall of fame? 😄

@RyanCavanaugh
Copy link
Member

That error looks like a bug. Do you have a repro? Or is it that there are two different DomElements?

@NoelAbrahams
Copy link

@RyanCavanaugh, there's only one DomElement. While implementing the interface there was a parameter clash with a type in lib.d.ts. Seems to be in the same ball park as this issue, but will take a look at producing a repro.

@DanielRosenwasser
Copy link
Member Author

We're almost there; #1798 is probably the next pain-point to tackle.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

6 participants