[Typescript] 85. Medium - IsInteger
typescript Medium 85
2023-09-14 09:00:44 时间
Please complete type IsInteger<T>
, type T
inherits from number
, if T
is an integer return it, otherwise return never
.
/* _____________ Your Code Here _____________ */
type IsInteger<T> = `${T & number}` extends `${number}.${number}`
? never
: number extends T
? never
: T;
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
let x = 1
let y = 1 as const
type cases1 = [
Expect<Equal<IsInteger<1>, 1>>,
Expect<Equal<IsInteger<1.1>, never>>,
Expect<Equal<IsInteger<1.0>, 1>>,
Expect<Equal<IsInteger<typeof x>, never>>,
Expect<Equal<IsInteger<typeof y>, 1>>,
]
相关文章
- typescript 多继承_说明类的继承和多态有什么作用
- typescript 接口_typeScript
- Typescript教程_安装typescript
- Getting Started: Ionic + Capacitor + React + Typescript + Android
- TypeScript基础知识
- TypeScript学习笔记(二)—— TypeScript基础
- TypeScript | 笔记
- typescript学习笔记
- (十四)与 TypeScript 集成
- Typescript 全栈最值得学习的技术栈 TRPC
- 【TypeScript】条件语句
- 调查:React 仍然是使用最广泛的前端框架,TypeScript 是优先选项
- TypeScript遭库开发者嫌弃:类型简直是万恶之源
- 调查:React 仍然是使用最广泛的前端框架,TypeScript 是优先选项