-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Nullish Coalescing and Logical Compound Assignments (??=, ||=, &&=) #37255
Copy link
Copy link
Closed
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueES NextNew featurers for ECMAScript (a.k.a. ESNext)New featurers for ECMAScript (a.k.a. ESNext)Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Metadata
Metadata
Assignees
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueES NextNew featurers for ECMAScript (a.k.a. ESNext)New featurers for ECMAScript (a.k.a. ESNext)Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Search Terms
Nullish coalescing assignment
Suggestion
A new operator
??=to assign some default to a variable/property if it is nullish.It's also avaibale in PHP: https://wiki.php.net/rfc/null_coalesce_equal_operator
Examples
obj1.obj2.obj3.x ??= 42;instead of
obj1.obj2.obj3.x = obj1.obj2.obj3.x ?? 42;Checklist
My suggestion meets these guidelines: