You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type '{ x: number; y: number; z: number; }' is not assignable to type 'Point'.
Object literal may only specify known properties, and 'z' does not exist in type 'Point'.
Actual behavior:
No errors thrown, but why? What is b: Point really saying? That b is of type Point or that b implements Point? Behaviorally, without throwing an error here, it's telling me that b implements Point. Syntactically, however, it's telling me that b is of type Point, which should be more strict, no?
Sorry for my lack of grammar.
Potential inconsistent behavior:
constc: Point={x: 5,y: 5,z: 5};
Expected and actual behavior:
An error is thrown.
Proposal
Be consistent? I don't see why x: T = y should be any different than a = y; x: T = a;. Is it crazy to request the following syntax for the implements case?
Consistency is not a pure virtue; it is only as good as the value it provides.
We could ignore excess properties in initialized variables. This used to be how it worked; people correctly complained that this was terrible behavior because if you declare a Point and initialize it with a z, we know the z effectively "goes missing"; from the type system's point of view that property initializer is evaluated for no reason and then vanishes forever. This was especially bad with optional properties as it's easy to misspell the property name and not get an error. It would be absolute madness to think about disallowing const b: Point = a; so I won't even go into that.
const a implements Point = { x: 5, y: 5, z: 5 }; // OK
TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx) or whatever's on the TypeScript Playground today.
Code
Expected behavior:
An error is thrown.
Actual behavior:
No errors thrown, but why? What is
b: Point
really saying? Thatb
is of typePoint
or thatb
implementsPoint
? Behaviorally, without throwing an error here, it's telling me thatb
implementsPoint
. Syntactically, however, it's telling me thatb
is of typePoint
, which should be more strict, no?Sorry for my lack of grammar.
Potential inconsistent behavior:
Expected and actual behavior:
An error is thrown.
Proposal
Be consistent? I don't see why
x: T = y
should be any different thana = y; x: T = a;
. Is it crazy to request the following syntax for theimplements
case?Just trying to offer a solution here, but I hate that it's not backwards compatible. I couldn't find any existing issues or discussions about this.
The text was updated successfully, but these errors were encountered: