1

I would like to do something like below

type TypeA<T> = (initialValue: T) => { ... }

const someFunc: <T>(TypeA<T>) = (initalValue) => {...} // doesn't work

someFunc<string>('Hello World')

Not

const someFunc:TypeA<string> = (initalValue) => {...}

Is this feasible?

Thank you for your time!

1 Answer 1

1

Your TypeA is a generic type (that happens to be a function). To assign a generic function, you should change the definition of TypeA:

type TypeA = <T>(initialValue: T) => {  }

const someFunc: TypeA = (initalValue) => { return {} }

Play

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.