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
I'm trying to upgrade some Typescript 2.0 code to 2.1 and running into an issue. It distills down to the following:
TypeScript Version: 2.1.4
Code
interfaceCommon{common: boolean;}interfaceAextendsCommon{a: A[];}interfaceBextendsCommon{b: B[];}letitems: (A[]|B[])=[];items.map(item=>item.common);// ErrorletotherItems: (A|B)[]=[];otherItems.map(item=>item.common);// No error
In both of these situations I would expect no error to occur. Regardless of whether the array has all the same type or a mixture of types, both can be simplified to Common[] which is valid. However, I get the following error:
Cannot invoke an expression whose type lacks a call signature. Type '{ <U>(this: [A, A, A, A, A], callbackfn: (value: A, index: number, array: A[]) => U, thisArg?: an...' has no compatible call signatures.
(A[] | B[]) is the type that truly matches what my data model is, since my code guaranteed that the array only contains one type of object. Therefore, I'd rather not use (A | B)[].
The text was updated successfully, but these errors were encountered:
I'm trying to upgrade some Typescript 2.0 code to 2.1 and running into an issue. It distills down to the following:
TypeScript Version: 2.1.4
Code
In both of these situations I would expect no error to occur. Regardless of whether the array has all the same type or a mixture of types, both can be simplified to
Common[]
which is valid. However, I get the following error:(A[] | B[])
is the type that truly matches what my data model is, since my code guaranteed that the array only contains one type of object. Therefore, I'd rather not use(A | B)[]
.The text was updated successfully, but these errors were encountered: