GreaterThan
介绍
实现类型GreaterThan<T, U>
, 就像T > U
一样. 负数不需要考虑.
ts
GreaterThan<2, 1> //should be trueGreaterThan<1, 1> //should be falseGreaterThan<10, 100> //should be falseGreaterThan<111, 11> //should be true
View on GitHubts
GreaterThan<2, 1> //should be trueGreaterThan<1, 1> //should be falseGreaterThan<10, 100> //should be falseGreaterThan<111, 11> //should be true
起点
ts
/* _____________ Your Code Here _____________ */typeGreaterThan <T extends number,U extends number> = any/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <1, 0>, true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <5, 4>, true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <4, 5>, false>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <0, 0>, false>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <10, 9>, true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <20, 20>, false>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <10, 100>, false>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <111, 11>, true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <1234567891011, 1234567891010>, true>>,]
take the challengets
/* _____________ Your Code Here _____________ */typeGreaterThan <T extends number,U extends number> = any/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <1, 0>, true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <5, 4>, true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <4, 5>, false>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <0, 0>, false>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <10, 9>, true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <20, 20>, false>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <10, 100>, false>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <111, 11>, true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <GreaterThan <1234567891011, 1234567891010>, true>>,]
解决方案
Spoiler warning // Click to reveal answer
ts
typeGreaterThan <T extends number,U extends number> = any
ts
typeGreaterThan <T extends number,U extends number> = any