Skip to content

inconsistent and misleading error message for type mismatch #719

@psnider

Description

@psnider

The following code:

interface HasDate {date: Date;}
var o : HasDate = {"date": "2014-05-01T14:00:00.000Z"}
var a : HasDate[] = [{"date": "2014-05-01T14:00:00.000Z"}]

when entered into the TypeScript Playground, produces the following errors:

/private/tmp/t.ts(2,5): error TS2012: Cannot convert '{ "date": string; }' to 'HasDate':
    Types of property 'date' of types '{ "date": string; }' and 'HasDate' are incompatible:
        Type 'String' is missing property 'toDateString' from type 'Date'.
/private/tmp/t.ts(3,5): error TS2012: Cannot convert '{}[]' to 'HasDate[]':
    Types of property 'pop' of types '{}[]' and 'HasDate[]' are incompatible:
        Call signatures of types '() => {}' and '() => HasDate' are incompatible:
            Type '{}' is missing property 'date' from type 'HasDate'.

Notice that the error for the plain object is correct, but the error for the array is incorrect and misleading, indicating that the field is missing, not that it is of the wrong type.

Details:

  • In line 3 of the second error, "Call signatures of types '() => {}' and '() => HasDate' are incompatible:", the reference "()" is unclear.
  • In line 4, "Type '{}' is missing property 'date' from type 'HasDate'.", is incorrect, as the date property is there.
  • I would like this second error to be very similar to the first error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions