前置的不定量参数
作者:xie392地址:https://v.douyin.com/ieQG2HdD/更新时间:2024-12-21
案例代码
1type JSTypeMap = {2string: string3number: number4boolean: boolean5object: object6function: Function7symbol: symbol8undefined: undefined9bigint: bigint10}1112type JSTYPENAME = keyof JSTypeMap1314type ArgsType<T extends JSTYPENAME[]> = {15[K in keyof T] : JSTypeMap[T[K]]16}171819declare function addImpl<T extends JSTYPENAME[]>(...args:[...T,(...args:ArgsType<T>)=>any]):void2021// addImpl('hello','world',()=>{}) // error: 不能将类型“"hello"”分配给类型“keyof JSTypeMap”。22// addImpl(1,2,3,()=>{}) // error: 不能将类型“1”分配给类型“keyof JSTypeMap”23addImpl('number',(a)=>{}) // true
目录