Question · JavaScript and React course · Module 12: React and TypeScript

Optional Props in TypeScript

How do you mark a prop as optional in a TypeScript interface?

Answer options

  • By adding the keyword optional before the name
  • By adding | null after the type
  • By using a question mark (?) after the field name
  • By setting the type to undefined

You can check the correct answer by solving this task in the CodeWorlds game.