Frage

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

interface IDirective{
    compile?:
        (templateElement: IAugmentedJQuery,

What does the ?: after compile do?

War es hilfreich?

Lösung

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top