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

Type '() => string' is not assignable to type 'string' in typescript

When I set following function,

const getIrohaTransaction:string = () =>{
    return "test";
}

following errors are alerted.

Type '() => string' is not assignable to type 'string'.
I still couldn’t understand the root cause of this error. What is the wrong point of this?If someone has opinion,please let me know. thanks

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

>Solution :

Empty input param is missing in your type definition:

const getIrohaTransaction: () => string = () =>{
    return "test";
}

In your case the getIrohaTransaction variable is defined as string whereas it should be marked as () => string which means a function that takes no arguments and returns a string.

TS Playground

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