重载Typescript中通用箭头功能的语法错误

时间:2019-02-06 01:43:05

标签: typescript generics arrow-functions

interface Foo1 {
  (param: number): number
  (param: string): string
}

const foo1: Foo1 = (param: number | string) => param as any
const foo2 = <T>(param: T) : T => param 

interface Foo3<T1, T2> {
  (param: T1): T1
  (param: T2): T2
}

const foo3: Foo3<T1, T2> = <T1, T2>(param: T1 | T2) => param as any
// [ts] Cannot find name 'T1'. [2304]
// [ts] Cannot find name 'T2'. [2304]

我在StackOverflow上进行了搜索,但是问题只谈论其中一个,或者没有回答问题。

0 个答案:

没有答案