Reputation: 59525
Currently I have this example which demonstrates conditional arguments, The value of the second argument passed in will depend on what the type of the first is.
type Check<G, T> = T extends number ? string : number
function Example<T>(arg: T) {
return function <P>(arg: Check<P, T>) {
}
}
// Valid:
Example('hello')(1)
Example(1)('hello')
How can I change the code above to make this example work?
Example()(1)
Example(1)()
The issue when I add ?
it make's it permanently optional, and without it its required.
Upvotes: 2
Views: 79
Reputation: 59525
void
does the trick!
type Check<G, T> = T extends number ? void : number
function Example<T>(arg?: T) {
return function <P>(arg: Check<P, T>) {
}
}
Example()(1)
Example(1)()
Upvotes: 2