Skip to content

Declare local variable as optional #13321

@tinganho

Description

@tinganho

Every time I type an undefinable variable, I think I typed something wrong:

let a: string | undefined;

Why do I think I did something wrong? It's because I never add undefined type to a union type as above except in variable declarations.

Don't you think it is time, introduce the optional operator to local variable declarations as well?

let a?: string;

The above syntax feel very natural and idiomatic typescript for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions