#How to conditionally make a parameter optional
25 messages · Page 1 of 1 (latest)
@vapid tundra when doing it void it still wants a 4th parameter by not making it optional
what are overloads?
!hb overloads
... bad link
How to create a d.ts file for a module
Learn about how Functions work in TypeScript.
Huh, I thought I'd seen someone using void with a conditional type to do that...
Preview:```ts
function foo<T extends "now" | "after">(
timing: T,
...[duration]: T extends "after" ? [string] : [void]
) {}
foo("now")
foo("after", "")```
Very ugly, but...
@vapid tundra Oh it has to be a rest parameter
Ahhh
genius
when you use extends in a type it for some reason loses context of which propeties actually exist on the object
even if both types just have one propety difference
wreidly
uhhm
Could probably use [] instead of [void], more semantically correct anyways