What Does? : Mean in Typescript?

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

interface IDirective{
    compile?:
        (templateElement: IAugmentedJQuery,

What does the ?: after compile do?

1

2 Answers

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

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest