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
import*asreflectfrom'jsii-reflect';// Version ^1.5.0exporttypeApiElement=reflect.Type|reflect.TypeMember|reflect.EnumMember;exportinterfaceData{readonlyelement: ApiElement;}// Note: reflect.Method and reflect.Initializer both directly or indirectly implement reflect.TypeMemberexportfunctiondoSomething<Textends(reflect.Method|reflect.Initializer)>(element: T): Data{if(reflect.Method.isMethod(element)){// Type 'T & Method' is not assignable to type 'Type'.return{ element };}if(reflect.Initializer.isInitializer(element)){// Type 'T & Initializer' is not assignable to type 'Type'.return{ element };}// Type checking absolutely fine - why'd previous ones not?return{ element };}
Expected behavior:
It should work like it did in TypeScript 3.8
Actual behavior:
$ tsc --build
lib/index.ts:13:14 - error TS2322: Type 'T & Method' is not assignable to type 'ApiElement'.
Type 'T & Method' is not assignable to type 'Type'.
12 return { element };
~~~~~~~
lib/index.ts:6:12
6 readonly element: ApiElement;
~~~~~~~
The expected type comes from property 'element' which is declared here on type 'Data'
lib/index.ts:17:14 - error TS2322: Type 'T & Initializer' is not assignable to type 'ApiElement'.
Type 'T & Initializer' is not assignable to type 'Type'.
16 return { element };
~~~~~~~
lib/index.ts:6:12
6 readonly element: ApiElement;
~~~~~~~
The expected type comes from property 'element' which is declared here on type 'Data'
Note - I have tried two build a reproduction that does NOT involve importing the separate package - to no avail. Maybe I just didn't try hard enough, or maybe this problem is triggering only when using a locally defined union of types from a dependency?
In any case, here are pointers to the relevant types within the jsii-reflect library (1.5.0 release):
Well, the exact issue is that the new extra check in #37537 relies on empty intersections being removed (as per #36696) and that wasn't happening here.
TypeScript Version: 3.9.2, 4.0.0-dev.20200512
Search Terms: TS2322, "is not assignable to type"
Code
Expected behavior:
It should work like it did in TypeScript 3.8
Actual behavior:
Playground Link: I stored my repro at https://github.com/RomainMuller/TypeScript39-Bug (public)
Related Issues: It appears likely related to the breaking change in #37195 (but not certain)
The text was updated successfully, but these errors were encountered: