Skip to content

RequireArray ​

自 1.3.0 起

确保类型是数组。

签名 ​

typescript
type RequireArray<T> = T extends unknown[] ? T : never

参数 ​

参数描述
T要检查的类型

示例 ​

基本用法 ​

typescript
import type { RequireArray } from 'uni-types'

type Result = RequireArray<string[]> // string[]
type Failed = RequireArray<string> // never

联合类型 ​

typescript
type MaybeArray = string[] | number
type OnlyArray = RequireArray<MaybeArray> // string[]

只读数组 ​

typescript
type ReadonlyStrings = readonly string[]
type Result = RequireArray<ReadonlyStrings> // readonly string[]

相关 ​

基于 MIT 许可发布