找出TypeScript中的函数类型

米哈尔

我在TypeScript中有两种类型,例如:

type Function1 = (text: string) => number
type Function2 = (count: number) => string

接下来,我有一些功能:

const myFunction = (text: string) => 7 // type Function1

如何找出函数的类型(Function1Function2)?

if (myFunction instanceof Function1) // Not working.
if ('property' in myFunction) // ...?
瑞安·卡瓦诺(Ryan Cavanaugh)

这是不可能的。类型在编译期间被擦除;您不能检查运行时值并确定对其进行注释的类型。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章