Optional parameters on TypeScript interfaces

The short answer is yes. Customer correctly implements Person since all fields of the interface are optional. Any object will correctly implement the interface.

The usefulness of this interface is:

  • On the implementer site, if any optional field is declared, the type must correspond (so phone has to be defined as number)
  • On the receiving side (for example, as a function parameter), you can only access fields that are potentially part of Person (you should check if they are undefined), but the function, for example, guarantees it will not access any other fields of a Person parameter.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)