GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — nullish coalescing commit by Kingwl · Pull Request #32883 · microsoft/TypeScript

Conversation

@Kingwl

@Kingwl Wenlu Wang (Kingwl) commented Aug 14, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

follow https://tc39.es/proposal-nullish-coalescing/

Introduction
This document specifies the nullish coalescing operator ??. See the explainer for an introduction.

The main design decisions made in this specification are:

The right argument of ?? is evaluated only if needed ("short circuiting").
?? has lower precedence than ||.
?? cannot immediately contain, or be contained within, an && or || operation.
The right argument is selected if the left argument is null or undefined.

Fixes #26578

TODO:

  • migrate & regression by Wenlu Wang (@Kingwl) Titian Cernicova-Dragomir (@dragomirtitian)
  • scanner & parser, by Ron Buckton (@rbuckton)
  • binder, by Ron Buckton (@rbuckton)
  • checker, by Ron Buckton (@rbuckton)
  • grammar checker by Wenlu Wang (@Kingwl)
  • transformer, by Ron Buckton (@rbuckton) Titian Cernicova-Dragomir (@dragomirtitian)
  • factory by Wenlu Wang (@Kingwl)
  • quick fix & refactor Titian Cernicova-Dragomir (@dragomirtitian) Wenlu Wang (@Kingwl)
  • tests, tests, tests, tests by Wenlu Wang (@Kingwl) Titian Cernicova-Dragomir (@dragomirtitian)
  • vscode highlight (Support option chaining syntax highlighting TypeScript-TmLanguage#522)
  • ? new quick fix

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jack-williams, HairyRabbit, fuafa, AlCalzone, dragomirtitian, j-oliveras, alitaheri, DanielRosenwasser, phenomnomnominal, juanpicado, and 44 more reacted with thumbs up emoji fatcerberus, j-oliveras, alitaheri, DanielRosenwasser, mucsi96, alexdresko, nathanph, MattiasBuelens, styfle, ExE-Boss, and 19 more reacted with hooray emoji AlCalzone, dragomirtitian, j-oliveras, alitaheri, DanielRosenwasser, juanpicado, pilioussis, aleclarson, ra100, alexdresko, and 20 more reacted with heart emoji AviVahl, j-oliveras, alitaheri, DanielRosenwasser, juanpicado, aleclarson, strax, alexdresko, nathanph, styfle, and 11 more reacted with rocket emoji ihailong, NE-SmallTown, and aiherrera reacted with eyes emoji
All reactions
  • 👍 54 reactions
  • 🎉 29 reactions
  • ❤️ 30 reactions
  • 🚀 21 reactions
  • 👀 3 reactions
@Kingwl Wenlu Wang (Kingwl) changed the title migrate nullish coalescing commit nullish coalescing commit Aug 14, 2019
@Kingwl
migrate nullish coalescing commit
2ef3e0f
@Kingwl
Wenlu Wang (Kingwl) force-pushed the nullish-coalescing-operator branch from b33eeac to 2ef3e0f Compare August 14, 2019 08:47
Wenlu Wang (Kingwl) added 5 commits August 14, 2019 17:08
@Kingwl
add more test case
91a04ed
@Kingwl
add branch type check test
ba39ae8
@Kingwl
add more tests
079d002
@Kingwl
fix nullish precedence
3822fde
@Kingwl
update public api
f67e524
@AlCalzone

AlCalzone commented Aug 14, 2019

Copy link
Copy Markdown
Contributor

Is this the real life? 😍

jpvillaseca, mickdekkers, alexdresko, acshef, xorets, rossleonardy, ronhuang, OG84, a-x-, agrinko, and 7 more reacted with laugh emoji
All reactions
  • 😄 17 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheetalkamat Sheetal Nandi (sheetalkamat) self-assigned this Aug 14, 2019
@Kingwl
add rescan question question token to fix regression
2327b3b
@Kingwl

Wenlu Wang (Kingwl) commented Aug 15, 2019

Copy link
Copy Markdown
Contributor Author

TypeScript Bot (@typescript-bot) test this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 15, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Wenlu Wang (@Kingwl), I've started to run the extended test suite on this PR at 2327b3b. You can monitor the build here. It should now contribute to this PR's status checks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Kingwl
update public api baseline
fb0d3c9
DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) reviewed Aug 15, 2019
View reviewed changes
Comment thread src/compiler/checker.ts
leftType;
case SyntaxKind.QuestionQuestionToken:
return getTypeFacts(leftType) & TypeFacts.EQUndefinedOrNull ?
getUnionType([getNonNullableType(leftType), rightType], UnionReduction.Subtype) :

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Aug 15, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to also return a union type for when strictNullChecks is off?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Kingwl Wenlu Wang (Kingwl) Aug 16, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to say yes, every value could be null/undefined if strictNullChecks is off and we cannot detect that.

same as:

declare const a: string
let b = a || 1 // b is string || number

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) reviewed Aug 15, 2019
View reviewed changes
Comment thread src/compiler/factory.ts Outdated
return createBinary(left, SyntaxKind.BarBarToken, right);
}

export function createNullishCoalescing(left: Expression, right: Expression) {

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Aug 15, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: createNullishCoalesce? I dunno, what do you think Ron Buckton (@rbuckton)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) reviewed Aug 15, 2019
View reviewed changes

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Progress looks great!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/baselines/reference/nullishCoalescingOperator1.js Outdated

//// [nullishCoalescingOperator1.js]
"use strict";
var aa1 = typeof a1 !== "undefined" && a1 !== null ? a1 : 'whatever';

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Aug 15, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a heads up, we might want to just go with a1 != null, since document.all is a weird anomaly of the language anyway that should ideally never be used in a ?? expression.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@arusakov Alexander Rusakov (arusakov) Nov 6, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daniel Rosenwasser (@DanielRosenwasser)
Sorry for the late comment after TypeScript 3.7 release.
But what about the shorter implementation of ?? operator that you have suggested?
This implementation with less code is better for all of us, I think.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Aug 15, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

.js emit test cases I'd like you to consider when targeting ESNext:

declare let a: any, b: any, c: any;

let x1 = (a ?? b as any) || c;
let x2 = c || (a ?? b as any);
let x3 = ((a ?? b) as any) || c;
let x4 = c || ((a ?? b) as any);
let x5 = (a ?? b) as any || c;
let x6 = c || (a ?? b) as any;

let y1 = (a ?? b as any) && c;
let y2 = c && (a ?? b as any);
let y3 = ((a ?? b) as any) && c;
let y4 = c && ((a ?? b) as any);
let y5 = (a ?? b) as any && c;
let y6 = c && (a ?? b) as any;
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Titian Cernicova-Dragomir (dragomirtitian) added 3 commits August 15, 2019 18:02
@dragomirtitian
Added tests that emit for nullish coalescing operator conforming with…
06149d0
… grammar restrictions when assertions are used.
@dragomirtitian
Fixed emit to hoist temporary variables (they previously went undecla…
3d94652
…red).

Added tests to ensure calls and property accesses are only called once.
@dragomirtitian
Merge branch 'nullish-coalescing-operator' of https://github.com/King…
65b2008
…wl/TypeScript into nullish-coalescing-operator
@dragomirtitian

Titian Cernicova-Dragomir (dragomirtitian) commented Aug 15, 2019

Copy link
Copy Markdown
Contributor

Daniel Rosenwasser (@DanielRosenwasser) I've added the tests, emit appears to work as expected keeping the () around the a ?? b. So as to conform to the grammar requirement that:

?? cannot immediately contain, or be contained within, an && or || operation.

Hope I didn't miss the point of the tests 😅

Ron Buckton (@rbuckton) or Daniel Rosenwasser (@DanielRosenwasser)
One thing I noticed was that emit is using the actual identifier in the down level version of ??. So x ?? 0 becomes typeof x !== undefined && x !== null ? x : 0.

But if x comes from an import, because of the order in which the transformations are applied, we might get side effects on the access to x:

//test2.ts
let x = { y: 1, x: 0 }
let v = 0;
Object.defineProperty(x, "x", {
    get() {
        return v++;
    }
})
export = x;
//usage.ts
import { x, y } from './test2'
let xo = x ?? "NO"
console.log(xo);
let yo = y ?? "NO"
console.log(yo);

This will output 2 and 1 because let xo = x ?? "NO" becomes var xo = typeof test2_1.x !== "undefined" && test2_1.x !== null ? test2_1.x : "NO"; which will call the getter multiple times.

I would just use the approach babel uses, use a temporary variable always ex. Thoughts ?

DanielRosenwasser, ckknight, Kingwl, and DioneMo reacted with thumbs up emoji
All reactions
  • 👍 4 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Aug 15, 2019

Copy link
Copy Markdown
Member

I think "use a temporary unless it's an identifier" is usually the approach we take.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dragomirtitian

Titian Cernicova-Dragomir (dragomirtitian) commented Aug 15, 2019

Copy link
Copy Markdown
Contributor

Daniel Rosenwasser (@DanielRosenwasser) Mkay 😕, so ignore the corner case above ?

Just to make sure I was clear in what I was trying to say x ?? "NO" is seen as using an identifier in the esnext transform, but the commonJS transformation will effectively turn it into test2_1.x ?? "NO" (with the actual result being typeof test2_1.x !== "undefined" && test2_1.x !== null ? test2_1.x : "NO"; )

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Kingwl
Merge pull request #1 from dragomirtitian/nullish-coalescing-operator
e4497b8
Nullish coalescing operator
@Kingwl Wenlu Wang (Kingwl) mentioned this pull request Aug 16, 2019
[TypeScript] Nullish coalescing highlight support microsoft/vscode#79279
Closed
Wenlu Wang (Kingwl) added 2 commits August 16, 2019 15:09
@Kingwl
use not equal to null
c2e336b
@Kingwl
rename factory
b714a01
@Kingwl

Wenlu Wang (Kingwl) commented Aug 16, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Titian Cernicova-Dragomir (@dragomirtitian)
I prefer it to be a side effect (or feature) of cjs.
not only this one but also many other syntaxes.

But i felt assign to temp variable is better

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Kingwl
add grammar check
323ebf0
@Kingwl

Wenlu Wang (Kingwl) commented Sep 20, 2019

Copy link
Copy Markdown
Contributor Author

TypeScript Bot (@typescript-bot) pack this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 20, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Wenlu Wang (@Kingwl), I've started to run the tarball bundle task on this PR at 57be95d. You can monitor the build here. It should now contribute to this PR's status checks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 20, 2019

Copy link
Copy Markdown
Contributor

Hey Wenlu Wang (@Kingwl), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/44785/artifacts?artifactName=tgz&fileId=64FF4F06CBE74357042C0E22BEF9D252966E889A57B59FEB9CE7822F7DA3784002&fileName=/typescript-3.7.0-insiders.20190920.tgz"
    }
}

and then running npm install.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) reviewed Sep 20, 2019
View reviewed changes
Comment thread src/compiler/types.ts
@@ -1502,6 +1503,7 @@ namespace ts {
export type LogicalOperator

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Sep 20, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually kind of strange because it's not really a LogicalOperator. Should it be moved out?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) reviewed Sep 26, 2019
View reviewed changes

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to update the API baselines?

We'd really like to merge this in by tomorrow for the beta. There seem to be only minor issues (control flow analysis not being entirely correct), but those can be fixed by the RC.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/transformers/esnext.ts
}

function createNotNullCondition(node: Expression) {
return createBinary(

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Sep 26, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since optional chaining uses strict equality, can you switch this to strict equality?

createBinary(
    createBinary(
        temp
        createToken(SyntaxKind.ExclamationEqualsEqualsToken),
        createNull()
    ),
    createToken(SyntaxKind.AmpersandAmpersandToken),
    createBinary(
        temp,
        createToken(SyntaxKind.ExclamationEqualsEqualsToken),
        createVoidZero()
    )
);

(Ron Buckton (@rbuckton))

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
rbuckton
Ron Buckton (rbuckton) suggested changes Sep 26, 2019
View reviewed changes
Comment thread src/compiler/binder.ts
(<BinaryExpression>node).operatorToken.kind === SyntaxKind.AmpersandAmpersandToken ||
(<BinaryExpression>node).operatorToken.kind === SyntaxKind.BarBarToken);
(<BinaryExpression>node).operatorToken.kind === SyntaxKind.BarBarToken ||
(<BinaryExpression>node).operatorToken.kind === SyntaxKind.QuestionQuestionToken);

@rbuckton Ron Buckton (rbuckton) Sep 26, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? isn't really a logical operator. This results in control-flow treating the branch as something "truthy" not something defined/undefined.

I'd like to see some tests for control flow.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Kingwl

Wenlu Wang (Kingwl) commented Sep 27, 2019

Copy link
Copy Markdown
Contributor Author

I’ll update that today

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Wenlu Wang (Kingwl) added 4 commits September 27, 2019 10:44
@Kingwl
update baseline
78df31b
@Kingwl
Merge branch 'nullish-coalescing-operator' of github.com:Kingwl/TypeS…
9e3852e
…cript into nullish-coalescing-operator
@Kingwl
update emitter and more testcase
de81520
@Kingwl
update control flow
6418943
DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) reviewed Sep 27, 2019
View reviewed changes
Comment thread src/compiler/checker.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Wenlu Wang (Kingwl) added 3 commits September 27, 2019 18:18
@Kingwl
make linter happy
a719f66
@Kingwl
update libs
cb187cb
@Kingwl
avoid unnecessary assert
7fd8658
robpalme
Rob Palmer (robpalme) reviewed Sep 27, 2019
View reviewed changes

@robpalme Rob Palmer (robpalme) left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some trivial things.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/binder.ts Outdated
bindCondition(node.right, trueTarget, falseTarget);
}

function bindNullishCollasingExpression(node: BinaryExpression, trueTarget: FlowLabel, falseTarget: FlowLabel) {

@robpalme Rob Palmer (robpalme) Sep 27, 2019

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: bindNullishCollasingExpression -> bindNullishCoalescingExpression

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Kingwl reacted with laugh emoji
All reactions
  • 😄 1 reaction
Comment thread src/compiler/binder.ts
function bindBinaryExpressionFlow(node: BinaryExpression) {
const operator = node.operatorToken.kind;
if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.BarBarToken) {
if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.BarBarToken || operator === SyntaxKind.QuestionQuestionToken) {

@robpalme Rob Palmer (robpalme) Sep 27, 2019

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This if-chain would be easier to read as a switch

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mklef121 and nxpatterns reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@Kingwl Wenlu Wang (Kingwl) Sep 27, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep this because of so many other code similar to that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/scanner.ts Outdated
pos++;
return token = SyntaxKind.GreaterThanToken;
case CharacterCodes.question:
if (text.charCodeAt(pos + 1) === CharacterCodes.question) {

@robpalme Rob Palmer (robpalme) Sep 27, 2019

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If you re-order the pos++ before the if, the code become marginally simpler.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Kingwl Wenlu Wang (Kingwl) Sep 27, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to be consistent with the existed code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Kingwl
fix typooo
6ef160f
DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) approved these changes Sep 27, 2019
View reviewed changes
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) added this to the TypeScript 3.7.0 milestone Sep 30, 2019
Ron Buckton (rbuckton) added 2 commits September 30, 2019 14:23
@rbuckton
Merge branch 'master' into nullish-coalescing-operator
8c572b1
# Conflicts:
#	src/compiler/scanner.ts
#	src/compiler/transformers/esnext.ts
#	src/compiler/utilities.ts
#	tests/baselines/reference/api/tsserverlibrary.d.ts
#	tests/baselines/reference/api/typescript.d.ts
@rbuckton
Fixes for control-flow analysis
b030f73
rbuckton
Ron Buckton (rbuckton) approved these changes Sep 30, 2019
View reviewed changes
@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) merged commit 7c50bcc into microsoft:master Sep 30, 2019
@j-oliveras Jordi Oliveras Rovira (j-oliveras) mentioned this pull request Oct 1, 2019
Add support for Optional Chaining #33294
Merged
@rbuckton

Ron Buckton (rbuckton) commented Oct 2, 2019

Copy link
Copy Markdown
Contributor

Wenlu Wang (@Kingwl): Thanks for the contribution!

My changes were mostly to merge the control-flow behavior of nullish-coalesce with the control-flow behavior of optional chaining and to resolve merge conflicts so that this could be merged with master for the 3.7 beta. Thanks again for all of the hard work!

ExE-Boss, Kingwl, and kirintwn reacted with thumbs up emoji Kingwl reacted with laugh emoji Kingwl reacted with hooray emoji Kingwl reacted with heart emoji
All reactions
  • 👍 3 reactions
  • 😄 1 reaction
  • 🎉 1 reaction
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@wsmd

Waseem Dahman (wsmd) commented Nov 6, 2019

Copy link
Copy Markdown

Thank you all for your hard work on this and congrats on the 3.7 release!

I have a small question out of curiosity. For foo ?? bar, was document.all the reason for choosing foo !== null && foo !== void 0 as the conditional expression in the compiled output, as opposed to the abstract equality comparison foo != null? 😅

let x = (foo !== null && foo !== undefined) ? foo : bar;
// vs
let x = foo != null ? foo : bar;
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Kingwl
Wenlu Wang (Kingwl) deleted the nullish-coalescing-operator branch November 6, 2019 11:20
@Kingwl

Wenlu Wang (Kingwl) commented Nov 6, 2019

Copy link
Copy Markdown
Contributor Author

was document.all the reason for
Waseem Dahman (@wsmd)
#32883 (comment)
#32883 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jcalz Joe Calzaretta (jcalz) mentioned this pull request Jan 24, 2020
Nullish coalescing should always include the type of the right operand #36393
Open
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@sheetalkamat Sheetal Nandi (sheetalkamat) sheetalkamat requested changes
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) DanielRosenwasser approved these changes
+3 more reviewers
@arusakov Alexander Rusakov (arusakov) arusakov left review comments
@robpalme Rob Palmer (robpalme) robpalme left review comments
@rbuckton Ron Buckton (rbuckton) rbuckton approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@sheetalkamat Sheetal Nandi (sheetalkamat)

Labels

None yet

Projects

None yet

Milestone

TypeScript 3.7.0

Development

Successfully merging this pull request may close these issues.

Nullish coalescing operator (??)

Uh oh!

There was an error while loading. Please reload this page.

12 participants

@Kingwl @AlCalzone @typescript-bot @DanielRosenwasser @dragomirtitian @weswigham @rbuckton @wsmd @arusakov @robpalme @sheetalkamat @RyanCavanaugh
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.