【发布时间】:2022-01-26 18:36:36
【问题描述】:
我想强制特定函数接受特定类型的第一个参数
type MyFunc = <Args extends []>(channelId: string, ...args: Args) => string
const doThing: MyFunc = (channelId: string, arg1: number, arg2: string) => arg1 + arg2
我收到以下错误
Type '(channelId: string, arg1: number, arg2: string) => string' is not assignable to type 'MyFunc'.
Types of parameters 'arg1' and 'args' are incompatible.
Type 'Args' is not assignable to type '[arg1: number, arg2: string]'.
Type '[]' is not assignable to type '[arg1: number, arg2: string]'.
Source has 0 element(s) but target requires 2.
【问题讨论】:
标签: typescript typescript-typings