-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhouzhenpan
committed
Aug 5, 2024
1 parent
54bd0d3
commit 1edb611
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ============= Test Cases ============= | ||
import type { Equal, Expect } from './test-utils' | ||
import { ExpectFalse, NotEqual } from './test-utils' | ||
|
||
let x = 1 | ||
let y = 1 as const | ||
|
||
type cases1 = [ | ||
Expect<Equal<Integer<1>, 1>>, | ||
Expect<Equal<Integer<1.1>, never>>, | ||
Expect<Equal<Integer<1.0>, 1>>, | ||
Expect<Equal<Integer<1.0>, 1>>, | ||
Expect<Equal<Integer<0.5>, never>>, | ||
Expect<Equal<Integer<28.0>, 28>>, | ||
Expect<Equal<Integer<28.101>, never>>, | ||
Expect<Equal<Integer<typeof x>, never>>, | ||
Expect<Equal<Integer<typeof y>, 1>> | ||
] | ||
|
||
// ============= Your Code Here ============= | ||
// type Integer<T extends number> = `${T}` extends `${infer F}.${infer R}` | ||
// ? R[number] extends 0 | ||
// ? F | ||
// : never | ||
// : Equal<T, number> extends true | ||
// ? never | ||
// : T | ||
|
||
type Integer<T extends string | number> = number extends T | ||
? never | ||
: `${T}` extends `${string}.${string}` | ||
? never | ||
: T | ||
|
||
type NumberToString<T extends number> = `${T}` | ||
|
||
type A1 = NumberToString<1.1> | ||
type A2 = NumberToString<1.0> |