

It is possible to use ?: with an undefined type. No errors when using question marks to define optional property Using ?: with undefined as type definition interface User ' but required in type 'User'.(2741) Hence, if we make a small modification to the User interface, the middleName property will have a type definition of string | undefined.

Similar to using two types where one type is undefinedĪnother way to think about using a question mark with a colon (?:) is to define two types to a property where one of them is undefined. That said, a property can either have a value based on the type defined or its value can be undefined. Using a question mark followed by a colon ( ?:) means a property is optional.

