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
/* eslint-disable */// The idea here is to propagate a primitive string union of event types// down a class hierarchy. The weird boilerplate is to keep TS // from automatically inferring to `string`.exporttypeEventInheritDefault={type: never};exporttypeEventInheritType={type: unknown};typeGetEvents<EventsextendsEventInheritType>=Events["type"]extendsstring
? Events["type"]
: never;exporttypeEventGetEvents<EextendsEventInheritType>=GetEvents<E>;exporttypeInheritEvents<Textendsstring,EextendsEventInheritType>={type: T|GetEvents<E>;};exportclassBase<Eventsextendsstring=string>{emitEvent(event: Events){}}exportclassA<EventsextendsEventInheritType=EventInheritDefault>extendsBase<EventGetEvents<InheritEvents<"one"|"two",Events>>>{}exportclassC<EventsextendsEventInheritType=EventInheritDefault>extendsA<InheritEvents<"three"|"four",Events>>{}constc=newC();constbase: Base=c;c.emitEvent("three");if(baseinstanceofC){// should be an errorbase.emitEvent("thre");// explicit cast does cause an errorconstcast=baseasC;cast.emitEvent("thre");}
π Actual behavior
The instanceof check resolved to C<any> instead of using the generic parameter's default.
π Expected behavior
The instanceof check should not resolve to C<any> and should produce an error when calling base.emitEvent("thre")
Additional information about the issue
It seems odd that an instanceof check would produce a different result then a cast. The following code actually does work correctly:
constC2=Cas{new(): C}if(baseinstanceofC2){// this now errors as expectedbase.emitEvent('thre')}
The text was updated successfully, but these errors were encountered:
π Search Terms
inference, generic, parameter, default
π Version & Regression Information
Behavior is the same in all version I tried.
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.2#code/PQKgBApgzgNglgOwC4FoAmcoEMBGMJgjABQxEAHgA4D2ATkmEgJ6UECiAbhMgJIIAWEWnCQARCADMsAVxgMAvGADejFhABcYBBC60wAXwDcZKnQbNWYTtyR9BwpABU1YRSosaw0hAGsE1AHcEA2NiDzAAcQgka2QoAB5YpChIciRuNBSkuyERZ1YAPlcrLjiAbQAiDwqAXVT0hEywKCRhBABzYjAwAH4SmyhK6pqusE1tXWMKGnpVSySomNLkxPqMrOWch3yIIsVFpIS2AqnTWfCtkUP4xzXGlJa29oAaKzum7IFcpzU95VGPJpbgAfSLRa7HYxGUjTMxgADGMCwUBSACFkRBEssUhQGk1Hoh2sUCR0ikpRhAALZXZYACh0Nk0hwAlMp9MR2SYZgxEciUgBBeKjQ7vDY2S4-SyKT72ETiKSyJDEIq49ZgdFQTELcHY+IS64VajaCpgUFVALUCqvQ4FW1smFnHlIlFgADCWIGov6vC+2xc0s2vrlkhkchVaTVgtG+t1VX4tAgEBNZok1GktCt3uSBWV9uI8KNLQRxW0ATdtOZxgLCCLOAxmg1BEU8NC8IAdFSaTZaXGE0nK8Q4BIwLS65qwIgWlgEPCINRh67WeTusBgM1+GmYGgwDgCNPILRaHRnqNV3MCIgJEJuLOwFI4Pht0hqF5x+1uLl4WBKFhaFhKdEQinmuaAhoqhjnmA847hiE4pO605MDm3RjhAHbUks3a9v2oQrmu0zwPCIgIsiDBoNQ0AkdI477kIR60KM1ZFvCpHFKhYDIm6xjdCxLToV2yA9kg8Y4RyxBAA
π» Code
π Actual behavior
The
instanceof
check resolved toC<any>
instead of using the generic parameter's default.π Expected behavior
The
instanceof
check should not resolve toC<any>
and should produce an error when callingbase.emitEvent("thre")
Additional information about the issue
It seems odd that an
instanceof
check would produce a different result then a cast. The following code actually does work correctly:The text was updated successfully, but these errors were encountered: