如何指示功能参数函数输入类型
我是打字稿的新手。 我的函数将功能作为输入参数。此输入参数函数具有数字输入值。
preloadResources(informLoadPct: Function)
{
let pct = 100;
informLoadPct(pct);
}
我称此函数为这样
preloadResources((loadedPercentage: number) => {
console.log(loadedPercentage);
});
,因为您可以看到功能参数是具有数字输入类型的函数。有没有办法定义这一点?
我们可以提供有关此功能的更多信息,而不是“ InformloadPct:功能”?
I am new to typescript.
I have a function that takes a function as an input parameter. This input parameter function has number input value.
preloadResources(informLoadPct: Function)
{
let pct = 100;
informLoadPct(pct);
}
I call this function like this
preloadResources((loadedPercentage: number) => {
console.log(loadedPercentage);
});
as you can see the function parameter is a function that has number input type. Is there a way to define that also?
instead of "informLoadPct: Function" can we provide more information about this function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你肯定可以。我最喜欢的方法是如下:
如果您需要在对象内传递此方法,则可以做同样的事情。
请参阅 typescript文档的更多信息。
You sure can. My prefered way is as follows:
If you ever need to pass this inside an object, you can do the same thing.
See more in the Typescript documentation.