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.
The following code:
when entered into the TypeScript Playground, produces the following errors:
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: