I found the following in a TypeScript declaration file for Angular:
interface IDirective{ compile?: (templateElement: IAugmentedJQuery,
What does the ?:
after compile do?
TypeScript 3.7 added support for the ?? operator, which is known as the nullish coalescing operator. We can use this operator to provide a fallback value for a value that might be null or undefined .
The question mark ? in typescript is used in two ways: To mention that a particular variable is optional. To pre-check if a member variable is present for an object.
What is the TypeScript exclamation mark? The non-null assertion operator tells the TypeScript compiler that a value typed as optional cannot be null or undefined . For example, if we define a variable as possibly a string or undefined, the !
The Angular safe navigation operator (?.) is a fluent and convenient way to guard against null and undefined values in property paths.
See: Walkthrough: Interfaces | TypeScript :: Describing Simple Types.
Basically, ?
marks the member as being optional in the interface.
(EDIT: As noted in comments, this is not restricted to interfaces.)
In this case, the ?:
is not a single operator, but rather two operators:
?
(optional),
:
(specify type).
In other languages/cases, ?:
would be the Elvis Operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With