What does ?: mean in Typescript?

Typescript

Typescript Problem Overview


I found the following in a TypeScript declaration file for Angular:

interface IDirective{
    compile?:
        (templateElement: IAugmentedJQuery,

What does the ?: after compile do?

Typescript Solutions


Solution 1 - Typescript

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.)

Solution 2 - Typescript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionErik ZView Question on Stackoverflow
Solution 1 - TypescriptAmadanView Answer on Stackoverflow
Solution 2 - TypescriptKarolDepkaView Answer on Stackoverflow