0
const example = <a, b> (o: (a) => b, c: (b) => a) => {

}

example(() => 1, (n) => n)

I'm looking for n to be assigned to number, but I get no warning.

1 Answer 1

2

Playing with this in the Typescript Playground, I came up with the following that seems to resolve the types the way you expect:

const example = <a, b>(o: ((arg1: a) => b), c: ((arg2: b) => a)) => {}

example(() => 1, (n) => n);

There are two differences here:

  1. I wrapped the example function argument types in parentheses to make them a little clearer (at least in my mind - I was having trouble wrapping my head around functions inside functions), and
  2. I added argument names (arg1 and arg2)

I'm reasonably sure that this is what you intended - I believe that a function type expression requires argument names. For example, the following results in a "Parameter has a name but no type. Did you mean 'arg0: a'?" error in the playground:

type f1 <a, b>(a) => b;
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.