题目
中文
在本挑战中, 你需要实现 GreaterThan<T, U>
, 它的作用像 T > U
你不需要考虑负数
示例:
GreaterThan < 2,
1 > //should be true
GreaterThan <
1,
1 > //should be false
GreaterThan <
10,
100 > //should be false
GreaterThan<111, 11>; //should be true
English
In This Challenge, You should implement a type GreaterThan<T, U>
like T > U
Negative numbers do not need to be considered.
For example
GreaterThan < 2,
1 > //should be true
GreaterThan <
1,
1 > //should be false
GreaterThan <
10,
100 > //should be false
GreaterThan<111, 11>; //should be true
Good Luck!
答案
type GreaterThan<
T extends number,
U extends number,
A extends any[] = []
> = A['length'] extends T
? false
: A['length'] extends U
? true
: GreaterThan<T, U, [...A, 0]>;
标签:Typescript,false,should,GreaterThan,体操,extends,true
From: https://www.cnblogs.com/laggage/p/type-challenge-greater-than.html