Type ‘null’ is not assignable to type ‘string’

In a TypeScript application ESLint flags code when we try to assign “null” value to string type variables and attributes. This can be necessary when we want to set the value of a database column to “null”.

To make a string type attribute nullable, add ” | null ” to the type definition:

export type Incident = {
  id: number;
  name: string;
  start_date_utc: string | null;
  end_date_utc: string | null;
  description: string;
}

Leave a comment

Your email address will not be published. Required fields are marked *