X Tutup
The Wayback Machine - https://web.archive.org/web/20210721151931/https://github.com/microsoft/TypeScript/pull/44842
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LKG to enable improved narrowing in 4.4. #44842

Merged
merged 2 commits into from Jul 1, 2021

Conversation

@DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Jul 1, 2021

Fixes #44841.

factory.inlineExpressions(compact([...pendingExpressions!, node])) :
factory.inlineExpressions(compact([...pendingExpressions, node])) :
Comment on lines -741 to +741

This comment has been minimized.

@DanielRosenwasser

DanielRosenwasser Jul 1, 2021
Author Member

This one is actually unfortunate - pendingExpressions is actually typed as never because we have an earlier assignment of undefined followed by a check for some(...) which is a type predicate on readonly T[]. Since you can't narrow down a readonly T[] from an undefined, it leaves us with never.

The real culprit is #9998, but it is also strange that we just allow a spread of type never.

@DanielRosenwasser
Copy link
Member Author

@DanielRosenwasser DanielRosenwasser commented Jul 1, 2021

I did notice one opportunity for a new narrowing: accessing a property on a non-null value.

When you write

if (foo!.bar) {
    // ...
}

You shouldn't have to repeat the foo! within the if since you'll have crashed by that point. In a sense, it's an implicit assertion on foo.

if (foo!.bar) {
  foo.bar.baz()
}

I think the only downside is that it's sometimes nice to ensure all uses of a variable look similar.

@DanielRosenwasser DanielRosenwasser requested review from ahejlsberg and sandersn Jul 1, 2021
Copy link
Member

@sandersn sandersn left a comment

How did you find all the places to remove !? Did the linter point them out for you?

@DanielRosenwasser
Copy link
Member Author

@DanielRosenwasser DanielRosenwasser commented Jul 1, 2021

At first it was manual just to get a sense of some patterns it would/wouldn't catch, but then yes, I ran gulp lint --fix.

@DanielRosenwasser DanielRosenwasser merged commit 9d443b7 into main Jul 1, 2021
10 checks passed
10 checks passed
@github-actions
build (10.x)
Details
@github-actions
CodeQL-Build
Details
@github-actions
CodeQL-Build
Details
@github-actions
build (12.x)
Details
@github-actions
build (14.x)
Details
@github-code-scanning
CodeQL 1 analysis not found
Details
@microsoft-cla
license/cla All CLA requirements met.
Details
@azure-pipelines
node10 Build #106052 succeeded
Details
@azure-pipelines
node12 Build #106050 succeeded
Details
@azure-pipelines
node14 Build #106051 succeeded
Details
@DanielRosenwasser DanielRosenwasser deleted the updateLkgForGreatNarrowing branch Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
X Tutup