Skip to content

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

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

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.

Activity

added this to the Community milestone on Dec 9, 2014
NoelAbrahams

NoelAbrahams commented on Dec 10, 2014

@NoelAbrahams

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

true 😃

DanielRosenwasser

DanielRosenwasser commented on Dec 10, 2014

@DanielRosenwasser
MemberAuthor

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

chrisbubernak commented on Dec 29, 2014

@chrisbubernak
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

DickvdBrink commented on Dec 30, 2014

@DickvdBrink
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

NoelAbrahams commented on Jan 23, 2015

@NoelAbrahams

@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

RyanCavanaugh commented on Jan 23, 2015

@RyanCavanaugh
Member

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

NoelAbrahams

NoelAbrahams commented on Jan 23, 2015

@NoelAbrahams

@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.

added
FixedA PR has been merged for this issue
and removed on Jan 31, 2015

3 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DickvdBrink@chrisbubernak@DanielRosenwasser@NoelAbrahams@RyanCavanaugh

        Issue actions

          Error messages are vague when types have the same name · Issue #1419 · microsoft/TypeScript