简体   繁体   中英

Typescript function returntype

I have this function declaration inside af module:

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

and then using it like this in a .ts file

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

But VSCode gives me this warning: Argument of type '(node: HTMLElement) => void' is not assignable to parameter of type 'HTMLElement' .

What should the returntype of the function then be? I'm not returning a value, but just using the node for reference.

If the usage of your component function is correct, the type should be declared as following where callback can be whatever name you prefer.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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