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
interfaceUser{name: string;age: number;};typeParam=ReadonlyArray<User>|User;// change to this will work:// type Param = Array<User> | User;functionprintObject(param: Param){if(Array.isArray(param)){console.log("array",param.length);}else{/* Property 'age' does not exist on type 'Param'. Property 'age' does not exist on type 'ReadonlyArray<User>'. [2339] */console.log("object",param.age);}}
Expected behavior:
$ tsc
Actual behavior:
$ tsc
index.ts(18,31): error TS2339: Property 'age' does not exist on type'Param'.
Property 'age' does not exist on type'ReadonlyArray<User>'.
Search Terms:
ReadonlyArray, inferr
Code
Expected behavior:
Actual behavior:
--
Playground Link:
http://www.typescriptlang.org/play/index.html#src=interface%20User%20%7B%0D%0A%09name%3A%20string%3B%0D%0A%09age%3A%20number%3B%0D%0A%7D%3B%0D%0Atype%20Param%20%3D%20ReadonlyArray%3CUser%3E%20%7C%20User%3B%0D%0A%2F%2F%20change%20to%20this%20will%20work%3A%0D%0A%2F%2F%20type%20Param%20%3D%20Array%3CUser%3E%20%7C%20User%3B%0D%0A%0D%0Afunction%20printObject(param%3A%20Param)%20%7B%0D%0A%09if%20(Array.isArray(param))%20%7B%0D%0A%09%09console.log(%22array%22%2C%20param.length)%3B%0D%0A%09%7D%0D%0A%09else%20%7B%0D%0A%09%09%2F*%0D%0A%09%09Property%20'age'%20does%20not%20exist%20on%20type%20'Param'.%0D%0A%09%09%09Property%20'age'%20does%20not%20exist%20on%20type%20'ReadonlyArray%3CUser%3E'.%20%5B2339%5D%0D%0A%09%09*%2F%0D%0A%09%09console.log(%22object%22%2C%20param.age)%3B%0D%0A%09%7D%0D%0A%7D
Related Issues:
The text was updated successfully, but these errors were encountered: