We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SO question
Playground
type ZERO = 0 type Next<T> = T extends ZERO ? { v: ZERO } : (T extends { v: infer U } ? { v: Next<U> } : never) type ONE = Next<ZERO> type TWO = Next<ONE> type THREE = Next<TWO> type FOUR = Next<THREE> type FIVE = Next<FOUR> type SIX = Next<FIVE> type SEVEN = Next<SIX> type EIGHT = Next<SEVEN> type NINE = Next<EIGHT> type TEN = Next<NINE> type TEq<T, P> = T extends P ? (P extends T ? true : never) : never let v1: TEq<TWO, TWO> = true // correct: types is equal let v3: TEq<SIX, SEVEN> = true // error: why type of v3 inferred as true? type Result = TEq<SIX, SEVEN> type Result_the_same_type = { v: { v: { v: { v: { v: { v: ZERO; }; }; }; }; }; } extends { v: { v: { v: { v: { v: { v: { v: ZERO }; }; }; }; }; }; } ? true : false // false /** * Why Result is true * and Result_the_same_type is false */
As you see Result and Result_the_same_type are structuraly equal.
Result
Result_the_same_type
Result is true Result_the_same_type is false
Result should be false
The text was updated successfully, but these errors were encountered:
See #35533 (comment)
Sorry, something went wrong.
Is there some workaround for this case?
@DarkGenius what about:
type AllowedLevels = 1 | 2 | 3 | 4 | 5; type Levels<T, Cache extends Array<any> = []> = { [P in keyof T]: T[P] extends object ? Levels<T[P], [...Cache, 1]> : Cache }[keyof T]; type Allowed<T> = Levels<T> extends { length: AllowedLevels } ? true : false; type Result=Allowed<SIX> // true type Result2=Allowed<SEVEN> // false
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
Bug Report
π Search Terms
SO question
β― Playground Link
Playground
π» Code
As you see
Result
andResult_the_same_type
are structuraly equal.π Actual behavior
Result is true
Result_the_same_type is false
π Expected behavior
Result should be false
The text was updated successfully, but these errors were encountered: