Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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'.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading