How do you mark a function parameter as optional in TypeScript?

TypeScript Associate Easy

TypeScript Associate — Easy

How do you mark a function parameter as optional in TypeScript?

Key points

  • The `?` symbol indicates that the parameter is optional.
  • Using the `optional` keyword is not the correct way to mark a parameter as optional.
  • Adding `| undefined` is used to allow a parameter to be either a specific type or `undefined`.
  • Wrapping in `Optional` is not a valid TypeScript syntax for marking a parameter as optional.

Ready to go further?

Related questions