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
Gives error Type 'ObjKeys & KeyIfSignatureOfObject<Obj, Key, ReturnTypeKeyof<Obj>> & Key' is not assignable to type 'string | number | symbol'.
π Expected behavior
No error; Key was constrained to AnyKey and should be usable as a key.
Additional information about the issue
I reduced this from a much larger example, so the code here doesn't make much sense (the names of the helper types might also not make sense anymore). It might be possible to reduce it further but I wasn't able to find anything obvious.
As the playground shows, simply wrapping the body of the type with a Key extends AnyKey check makes the error go away, which makes me think that this must be a bug (I guess it distributes the union, but the entire union should be valid as a key type). Checking Key extends ObjKeysbeforeKeyIfSignatureOfObject also makes the error go away.
The text was updated successfully, but these errors were encountered:
This one is quite subtle. We have logic in relationship checking that hoists union constraints of generic types in an intersection into a top-level union of intersections such that it can be properly related to another union. Because of the divide-and-conquer change, we break an intersection of four constituents into two intersections of two constituents. In the repro, one of those divided intersections so happens to qualify for constraint reduction (e.g. where T & string becomes just T because T extends string), and that in turn defeats the hoisting logic.
The fix is to not perform constraint reduction in intersections created for purposes of hoisting constraints. I'll put up a PR.
typeTest1<K1extendskeyofany,K2extendskeyofany>=MustBeKey<Extract<K1,keyofany>&K1&K2>;// No errortypeTest2<K1extendskeyofany,K2extendskeyofany>=MustBeKey<K1&K2&Extract<K1,keyofany>>;// Error, wat?typeMustBeKey<Kextendskeyofany>=K;
π Search Terms
generic type constraint not applied inside type
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.4.5#code/C4TwDgpgBAggdiA0hEUC8U4FcC2AjCAJygB8oBnYQgSzgHNSKR8B7AGwG4AoL0SKAEoRgWQnAAq4CMhAsAZgB4A8ngBWUCAA9gEOABNyUFmogBjYAD50UFeq079h46rPAuUD1AD8UANoBrFHkbNQBdDW1dAz84CAA3IlD3TxSfWITCZJSPAC4oAG8-GShaKEDZORD1AENDShp6UIBaLzyACgBKdCtigF9feto6JJS89KJuXikoGQBJOQBlajo4apFCCCU5W1cFLKqIh2jnVwAafeL7KMN4JBRzlKF1iSkZQwwn0RfIGXllNQs5ysH2EX0kPxQhiujignW6MxQ3lhbThaB6KC60OinzE4OkkKRxTG8SIXWJGUmWjALEIwCgfGgQj0WFMED0AEZ-nZIjCTuZTgjUFibggZAKAGrVNhYCAC2xvQ7XMpBSq2azlYK2YEXRHCwXzJYrNaiTbbEzmLkCmQWfapQWKmHygkAemdsDYAHdqiBDFQZQA6W3ZDw+Qq+RAlOCC0J5SXS6C9IPB8lEJNQFOESauqAAdRp-kM1EqphYcHq1VodOohg2TVMAAszIE9JHyNQ9NAGYGqTS6QzBGyWWyAExch3Hc3AK26nnRW5iqBxmVytQKvUa1VqdUqqralKXWciu4gNM+A9HQxzRbLVbrU07C22acgG3B4NnmcXqoK7MwT3e31CADNM31DIpI2jWMpRlKBEzfeCMxAzxEIQzASUzLggA
π» Code
π Actual behavior
Gives error
Type 'ObjKeys & KeyIfSignatureOfObject<Obj, Key, ReturnTypeKeyof<Obj>> & Key' is not assignable to type 'string | number | symbol'.
π Expected behavior
No error;
Key
was constrained toAnyKey
and should be usable as a key.Additional information about the issue
I reduced this from a much larger example, so the code here doesn't make much sense (the names of the helper types might also not make sense anymore). It might be possible to reduce it further but I wasn't able to find anything obvious.
As the playground shows, simply wrapping the body of the type with a
Key extends AnyKey
check makes the error go away, which makes me think that this must be a bug (I guess it distributes the union, but the entire union should be valid as a key type). CheckingKey extends ObjKeys
beforeKeyIfSignatureOfObject
also makes the error go away.The text was updated successfully, but these errors were encountered: