#Very simple question about generics and unions

1 messages · Page 1 of 1 (latest)

wise bone
#
export class PluginController<
  Settings extends GenericSettings | undefined = undefined,
> { //blablabla
}```
What does `undefined = undefined` mean in this context? Wouldn't that just return `true`?
#

Or in this context:

export interface PluginInstance<
  Settings extends GenericSettings | undefined = GenericSettings | undefined,
> {
// bla bla bla
}
woeful ridge
#

that's a default for the generic

half otterBOT
#
type X<T = "a"> = T;
type Y = X<number>;
//   ^? - type Y = number
type Z = X;
//   ^? - type Z = "a"
woeful ridge
#

kinda like how you do function argument defaults

wise bone
#

oooooooh

#

but wait

wise bone
#

In your example T isnt like undefined

woeful ridge
#

Wouldn't that just return true?
remember, equality checks are == in most programming languages

wise bone
#

oh right

woeful ridge
#
Settings
  extends GenericSettings | undefined
  = GenericSettings | undefined
wise bone
#

ooooh

#

i feel like some parenthesis would make that more clear

wise bone
woeful ridge
#

correct

wise bone
#

oki

#

thank you