Javascript TypeScript-Can';t将函数类型设置为重载
我试图将函数的类型设置为重载类型,该类型定义为接口的属性,但获取的Javascript TypeScript-Can';t将函数类型设置为重载,javascript,typescript,types,Javascript,Typescript,Types,我试图将函数的类型设置为重载类型,该类型定义为接口的属性,但获取的绑定元素“text”隐式具有函数参数的“any”类型。ts(7031)。重载都有相同的args类型,所以我不知道为什么会出错 接口参数{ 文本:字符串 } 接口UTIL{ toUpperCase?(args:args):字符串 toUpperCase?(args:args):任何 } 导出const toUpperCase:Utils['toUpperCase']=({text})=>text.toUpperCase() 它可
绑定元素“text”隐式具有函数参数的“any”类型。ts(7031)
。重载都有相同的args类型,所以我不知道为什么会出错
接口参数{
文本:字符串
}
接口UTIL{
toUpperCase?(args:args):字符串
toUpperCase?(args:args):任何
}
导出const toUpperCase:Utils['toUpperCase']=({text})=>text.toUpperCase()
它可以单独处理任意一个重载,因此如果我删除其中一个(不管是哪一个),那么错误就消失了,例如
接口Utils{
toUpperCase?(args:args):字符串
//toUpperCase?(args:args):任何
}
向函数参数添加一个:Args
显式键入似乎可以消除编译器错误
interface Args {
text: string
}
interface Utils {
toUpperCase?(args: Args): string
toUpperCase?(args: Args): any
}
export const toUpperCase: Utils['toUpperCase'] = ({ text }: Args) => text.toUpperCase()
似乎无法推断右侧的函数是否满足
Utils['toUpperCase']
的签名,但没有它。向函数参数添加:Args
显式键入似乎可以消除编译器错误
interface Args {
text: string
}
interface Utils {
toUpperCase?(args: Args): string
toUpperCase?(args: Args): any
}
export const toUpperCase: Utils['toUpperCase'] = ({ text }: Args) => text.toUpperCase()
似乎无法推断右侧的函数是否满足Utils['toUpperCase']
的签名