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
Expected behavior:
This code should pass with no errors.
Actual behavior:
Failed to compile with the following error.
Type '{ phoneNumbers: { __typename: string; }[]; }' is not assignable to type 'Person'.
Types of property 'phoneNumbers' are incompatible.
Type '{ __typename: string; }[]' is not assignable to type '{ __typename: "PhoneNumber"; }[]'.
Type '{ __typename: string; }' is not assignable to type '{ __typename: "PhoneNumber"; }'.
Types of property '__typename' are incompatible.
Type 'string' is not assignable to type '"PhoneNumber"'.
Workaround
function createPerson(): Person {
return {
phoneNumbers: [1].map(() => ({
__typename: 'PhoneNumber' as 'PhoneNumber'
}))
};
}
The text was updated successfully, but these errors were encountered:
deftomat
changed the title
Bad type inference with Array.map and explicit string type / union
Wrong type inference with Array.map and explicit string type / union
May 23, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.9.0-rc
Search Terms: union string map
Code
Expected behavior:
This code should pass with no errors.
Actual behavior:
Failed to compile with the following error.
Workaround
The text was updated successfully, but these errors were encountered: