IssueRaiser

Declare local variable as optional

Every time I type an undefinable variable, I think I typed something wrong: ```ts 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? ```ts let a?: string; ``` The above syntax feel very natural and idiomatic typescript for me.

Posted by tinganho on Jan 6, 2017, 11:45 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments

github (Other)

Declare local variable as optional

tinganhoJan 6, 2017, 11:45 AM

Every time I type an undefinable variable, I think I typed something wrong: ```ts 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? ```ts let a?: string; ``` The above syntax feel very natural and idiomatic typescript for me.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue