Skip to content

Incomprehensible error message when parameter clashes with type in Lib.d.ts #1798

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
NoelAbrahams opened this issue Jan 25, 2015 · 3 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@NoelAbrahams
Copy link

Hi,

TS: 1.4

The following code:

declare module foo {

    interface DragEvent {

        foo(): void;
        dataTransfer: DataTransfer;
    }

    interface Baz {

        bar(handler: (event: foo.DragEvent) => void): void;
    }

    interface BazInternal {

        equals(other: Baz): boolean;
    }
}

class Baz implements foo.BazInternal {

    public equals(other: Baz) {
        return true;
    }

    public bar(handler: (event: DragEvent) => void) {
    }
}

Causes the compiler to issue an incomprehensible error message:

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

The relevant items are:

  • The signature for public bar should have been public bar(handler: (event: foo.DragEvent) => void)
  • To reproduce the error, the interface foo.DragEvent should have an additional method foo(): void; (in order to distinguish it from the type in lib.d.ts)
  • For the line Type 'Baz' is not assignable to type 'Baz' to be printed there should be both a class and an interface called Baz.

Related issues: #1419 #1796

@DanielRosenwasser
Copy link
Member

Type 'Baz' is not assignable to type 'Baz'.

As this is related to #1419, #1575 should partially help with some of what you're seeing here.

@danquirk danquirk added the Bug A bug in TypeScript label Jan 26, 2015
@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Jan 31, 2015
@DanielRosenwasser DanielRosenwasser removed the Fixed A PR has been merged for this issue label Jan 31, 2015
@DanielRosenwasser
Copy link
Member

If we could actually get the Type 'Baz' is not assignable to type 'Baz'. portion fixed, then this would at least not be quite as crazy. Unfortunately we"re not doing that somewhere.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 22, 2016

this shoudl be fixed now. it shows:

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 'foo.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 'foo.DragEvent'.
Property 'foo' is missing in type 'DragEvent'.

@mhegazy mhegazy closed this as completed Feb 22, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Feb 22, 2016
@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 Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

4 participants