1

I've got the following types/interfaces:

type Nullable<T> = T | null;

export interface Employee {
  name: string;
  salary: number;
}

I don't want to define attributes of Employee to be Nullable, BUT the whole Employee should be Nullable.

Since I don't want do type everytime I use it as so Nullable<Employee>. I'd rather just type it as Employee which then would automatically be Employee | null

axel wolf
  • 1,446
  • 3
  • 18
  • 29

1 Answers1

4

You'll need a type alias :

export type Employee = {
  name: string;
  salary: number;
} | null
Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134