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
classA{staticEventTypes: {'eventName': [1,2],};declare['AA']: typeofA;test<KextendsA,FextendsK['AA']['EventTypes'],TextendskeyofF>(this: K,type: T,a: F[T]extendsany[] ? number : string// The inference here was not successful; the type should be determinable as either a number or a string.): F[T]{returnnullasany;}sendData(){vara=this.test('eventName','2');// String is not acceptable.a=[1,2]// F[T] is successfully inferred.varb=this.test('eventName',2);// Number is not acceptable.b=[2,3]// F[T] is successfully inferred.}}
π Actual behavior
Argument of type 'string' is not assignable to parameter of type 'this["AA"]["EventTypes"]["TCP:SEND_DATA"] extends any[] ? number : string'.
Argument of type 'number' is not assignable to parameter of type 'this["AA"]["EventTypes"]["TCP:SEND_DATA"] extends any[] ? number : string'.
Using the ?: operator, neither ifTrue nor ifFalse was selected. I am unsure of what type to pass in to satisfy the conditions.
π Expected behavior
I believe the ?: operator should never fail; it should always select and return one of the options.
Of course, in my test, I hope it returns a number.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
I believe the ?: operator should never fail; it should always select and return one of the options.
It's not failing, your type simply can't be resolved because the type of this is not known. It could be very well a subclass with a more constrained property. Such is the limitation with conditional types. When dealing with conditional types all involved types must be known, and what type this actually is is not known.
See also #51288 and other issues regarding this and conditional types.
π Search Terms
?:
π Version & Regression Information
v5.4.5
β― Playground Link
https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true#code/MYGwhgzhAECC0G8BQ1XQgFzBglsaAogG4CmAdhgCoCeADiRAFyIppsDkJpFAcmALYl2zANoBGADTQATAF0JrVAF8A3EkXQAJiVBgATiWgj2sWO1nMMdEgHsAZnDUaMDDAB4A0tBIAPF2U0YWCkAMW8-ckDoD2NTc2NiciprCHMpSnD-KIBrEmp7aBCAPgAKDTYMAAscJmiFNgrrZkp6htQwZhCRSllMyJgwMmoRXoB+aDIAV34AIxI9aGZMPRwyAHNoAHpN6EpKw1W7efJgQ32DaAB3SAmbDHRJ4FOoO0mQFWgqwyt6dEqbN6aaBzLQkFx6firMAzECGG4kHBfBZgCbTOYLGzI9AYFbrAB0GgAlJ1ur0ENADBhJnoyKiQCBoDdBtQPkp1GwIJEACLYMAlQksNqoIj6RnQAC8n2qEDxLkwJU43AwfEE7Ck7Gk7EJH220AAyjjVhsard7mAniRaFgYSQCUKxZLxFI5Fsdl0etATRBHs8IK96dRPWQjnoDJo7UKRQsZhKpTVZa4FVwkiqhM7ta7oDw0fNPTAyHdGRardDYRG2jHHdIpABmXq6929L0+hh+t4gQOHeZh8vQNlKIA
π» Code
π Actual behavior
Using the ?: operator, neither ifTrue nor ifFalse was selected. I am unsure of what type to pass in to satisfy the conditions.
π Expected behavior
I believe the ?: operator should never fail; it should always select and return one of the options.
Of course, in my test, I hope it returns a number.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: