繁体   English   中英

Typescript function 返回类型

[英]Typescript function returntype

我在 af 模块中有这个 function 声明:

declare module 'picoapp' {
  export function component(node?: HTMLElement): void
}

然后在.ts文件中像这样使用它

export default component((node: HTMLElement) => {
   // All sorts of TS/JS here
})

但是 VSCode 给了我这个警告: Argument of type '(node: HTMLElement) => void' is not assignable to parameter of type 'HTMLElement'

那么 function 的返回类型应该是什么? 我没有返回值,而只是使用节点作为参考。

如果您的组件 function 的用法是正确的,则应将类型声明如下,其中回调可以是您喜欢的任何名称。

 declare module 'picoapp' { export function component(callback:(node?: HTMLElement)=>void): void }

暂无
暂无

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

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