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
// A *self-contained* demonstration of the problem follows...exporttypeWebSocketMessage={type: 'userInfo'}|{type: 'chat'};exportletWSSend=(ws: WebSocket,message: WebSocketMessage)=>{};letws=newWebSocket('');letmessage={type: 'chat'};WSSend(ws,message);
Expected behavior:
No error. Noticed though that it passes:
Error:(13, 12) TS2345:Argument of type '{ type: string; }' is not assignable to parameter of type '{ type: "userInfo"; } | { type: "chat"; }'.
Type '{ type: string; }' is not assignable to type '{ type: "chat"; }'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"chat"'.
The text was updated successfully, but these errors were encountered:
It's because let message = {type: 'chat'} will by default infer as {type: string} which is not assignable to {type: 'userInfo'} | {type: 'chat'} which is using string literals.
There is a discussion about possible syntax for literals #10195
yeah, but IMO it should work as users would expect, which is no error without additional syntax. If it's not planned to be implemented at all, let's close the issue.
TypeScript Version: 2.1.0-dev.20160723
Code
Expected behavior:
No error. Noticed though that it passes:
Actual behavior:
The text was updated successfully, but these errors were encountered: