Appearance
任意类型(any)
any 可以看作一个包含所有类型的联合类型,所以它可以是任意一个类型
ts
type Null10 = "zs" extends any ? true : false // true
type Null11 = number extends any ? true : false // true
type Null12 = [string] extends any ? true : false // true
- 未初始化且没有申明类型的变量默认为 any
ts
let a // any 类型
- 函数未申明返回类型的 undefined | null,其返回类型为 any
ts
// 返回的结果类型为 any
const func10 = () => null // const func10 = () => any
type Func10ReturnType = MyReturnType<typeof func10> // any
// 返回的结果类型为 any
const func11 = () => undefined // const func10 = () => any
type Func11ReturnType = MyReturnType<typeof func11> // any
// 返回的结果类型为 number
const func12 = () => 1 // const func10 = () => number
type Func12ReturnType = MyReturnType<typeof func12> // number
// 返回的结果类型为 void
const func15 = () => {} // const func10 = () => void
type Func15ReturnType = MyReturnType<typeof func15> // void
// 显式的表明返回结果为 Null
type Func13 = () => null
type Func13ReturnType = MyReturnType<Func13> // null