Is there a way to make mapped type which takes optional or array values only

  Kiến thức lập trình

I have type:
type Primitive = number | string | boolean | object | symbol;
and a function which I want to be sure gets objects which have all properties of type Primitive | undefined or Primitive[] but which can’t have properties of type Primitive or undefined or null etc.
I tried type OptionalPrimitive = (number | undefined) | (string | undefined) | (boolean | undefined) | (object | undefined) | (symbol | undefined);
and later using it in mapped type:
[key: string]: OptionalPrimitive | Primitive[]; but it doesn’t work

LEAVE A COMMENT