Use typescript to type function argument and return full argument type

33 Views Asked by At

I have the following function and object as its input:

const myResult = myFunc({
  someInnerFunction: (innerArgument) => {
    return innerArgument.myProperty
  }
})

And a given type:

type MyType = {
  myProperty: number | boolean
}

How can i make sure myFunc types innerArgument as type MyType BUT ALSO types myResult as the equivalent to the type

{
  someInnerFunction(innerArgument: MyType): number | boolean
}

?

1

There are 1 best solutions below

2
Michael Lorton On

If I understand your question, just this:

declare function myFunc(p: {
  someInnerFunction: (innerArgument: MyType) => MyType['myProperty'];
}): void;