0

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

1
  • 1
    A function returning a string is not itself a string, no - that's not really a matter of opinion! Either the type of getIrohaTransaction needs to change entirely, or you need to move the : string to the return position. Commented Jul 27, 2022 at 10:21

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.