map
method.User[]
):gender: 'M' | 'F'
mean?gender: 'M' | 'F'
is a type annotation indicating that the property gender
can only have one of two string literal values: 'M'
or 'F'
.gender
, which are 'M'
or 'F'
. This helps prevent bugs by rejecting any invalid assignments (for example, any other string).|
(pipe) operator is used to define a union type. This allows the gender
property to be either 'M'
or 'F'
, but nothing else.