#required parameter based on type parameter value

1 messages · Page 1 of 1 (latest)

dusk pathBOT
#

@green lynx Here's a shortened URL of your playground link! You can remove the full link from your message.

ricmed#0

Preview:ts ... const result2 = add()

waxen sapphire
#

The never type does not mean a parameter is optional

#

If you want to mark a parameter as optional, use ?

#
function foo(bar?: number) {
}
green lynx
#

what I want is that if the type parameter is some type, the function accepts 0 arguments

waxen sapphire
#

Or use overloads for more complex signatures

#

You cannot make a check on a parameter you are not passing

green lynx
#

how would the function overload would look like for my needs?

#

(please see playground)

green lynx
#

got it working with rest parameters

waxen sapphire
dusk pathBOT