Alwaysblue
Alwaysblue

Reputation: 11830

typescript option type valid for null value interface

I have an interface like this

export interface Font {
  id: number
  table_definition_id: number
  auth: boolean | null 

The interface always have key auth with value boolean or null

If I change it to

export interface Font {
  id: number
  table_definition_id: number
  auth?: boolean 
}

Will this be valid?

Upvotes: 0

Views: 32

Answers (1)

Dooomel
Dooomel

Reputation: 586

It wouldn't be valid because then auth could be either boolean or undefined, never null

Upvotes: 1

Related Questions