#How to keep generic parameter as default if not needed?

1 messages · Page 1 of 1 (latest)

frozen roseBOT
#
0xc0c0a#0

Preview:```ts
function f<Id extends string = never>(options: {
id?: Id | undefined | null
}) {
return options
}

const a = f({id: "_id"})
// ^?
const b = f({id: null})
// ^?
const c = f({id: undefined})
// ^?```

modern zephyr
#

this is an XY problem but I am also just curious why it behaves like this

#

How to keep generic parameter as default if not needed?

sly stone
#

you generally should not have defaults on function generics, they don't really work with inference