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
Search Terms:
object type inference
incorrect type inference
Expected behavior:
When I have two interfaces that extend from the same base interface I should be able to check for the existence of a property within a variable that only exists in one of the two interfaces. TypeScript will not give an error saying that the property doesn't exist on the other type when I first check for its existence.
Actual behavior:
When I have two interfaces that extend from the same base interface I am not able to check for the existence of a property within a variable that only exists in one of the two interfaces. TypeScript will give an error saying that the property doesn't exist on the other type.
Related Issues:
Code
exporttypeProductDescription=|BagDescription|BeltDescription|ClothingDescription|ShoeDescription;exportinterfaceBaseDescription{brand: string;name: string;partner_catalogue_number: number;color: string;}exporttypeBagDescription=BaseDescription;exportinterfaceBeltDescriptionextendsBaseDescription{length: string;length_manufacturer: string;}exportinterfaceClothingDescriptionextendsBaseDescription{clothing_size_eu: string;clothing_size_manufacturer: string;}exportinterfaceShoeDescriptionextendsBaseDescription{shoe_size_eu: string;shoe_size_manufacturer: string;}// a response from an API request// unkown what description will beconstdescription: ProductDescription={}asProductDescription;// ts error while I expect this to work// Property 'shoe_size_eu' does not exist on type 'ProductDescription'.// Property 'shoe_size_eu' does not exist on type 'BagDescription'if(description.shoe_size_eu)console.log(description.shoe_size_eu)// not a ts errorif("shoe_size_eu"indescription)console.log(description.shoe_size_eu)
Output
// a response from an API request// unkown what ProductDescription will beconstdescription={};if(description.shoe_size_eu)console.log(description.shoe_size_eu);if("shoe_size_eu"indescription)console.log(description.shoe_size_eu);
TypeScript Version: 3.9.2
Search Terms:
object type inference
incorrect type inference
Expected behavior:
When I have two interfaces that extend from the same base interface I should be able to check for the existence of a property within a variable that only exists in one of the two interfaces. TypeScript will not give an error saying that the property doesn't exist on the other type when I first check for its existence.
Actual behavior:
When I have two interfaces that extend from the same base interface I am not able to check for the existence of a property within a variable that only exists in one of the two interfaces. TypeScript will give an error saying that the property doesn't exist on the other type.
Related Issues:
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: