繁体   English   中英

在 typescript 类型中将 function 标记为 function

[英]Marking function as function in typescript type

我正在尝试为组件道具声明类型,如下所示

type TSPaymentFormProps = {
paymentAmountType: string,
totalAmount: number,
prolongationAmount: number,
currentProcListInfo: object,
customAmount: number,
invalidAmount: boolean,
handleAmountChange: any,
setPaymentType: function

}

最后一个应该标记为 function 但我收到错误cannot find name 'function' 我该怎么做?

To define a type as a function in TypeScript we use Function something like this setPaymentType: Function which generalize it to any function and not the best approach. 要更详细地指定setPaymentType: (param1: <Param Type>, param2: <Param Type>) => <Return Type>类型,它的参数类型和返回类型定义如下并且不返回任何我们可以将其写为setPaymentType: () => void

你可以这样做setPaymentType: () => void

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM