Skip to content

{} & null and {} & undefined should always be never #50553

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

Merged
merged 4 commits into from
Sep 1, 2022
Merged

Conversation

ahejlsberg
Copy link
Member

Fixes #50519.

@ahejlsberg
Copy link
Member Author

@typescript-bot test this
@typescript-bot user test this inline
@typescript-bot run dt
@typescript-bot perf test faster
@typescript-bot test top100

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 30, 2022

Heya @ahejlsberg, I've started to run the extended test suite on this PR at dd32cf8. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 30, 2022

Heya @ahejlsberg, I've started to run the diff-based user code test suite on this PR at dd32cf8. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 30, 2022

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at dd32cf8. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 30, 2022

Heya @ahejlsberg, I've started to run the abridged perf test suite on this PR at dd32cf8. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 30, 2022

Heya @ahejlsberg, I've started to run the diff-based user code test suite on this PR at dd32cf8. You can monitor the build here.

Update: The results are in!

@Gadrawingz
Copy link

I'm willing to join

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the user test suite comparing main and refs/pull/50553/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

@ahejlsberg
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..50553

Metric main 50553 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 338,723k (± 0.01%) 338,737k (± 0.00%) +14k (+ 0.00%) 338,698k 338,759k
Parse Time 2.06s (± 0.53%) 2.07s (± 1.04%) +0.01s (+ 0.49%) 2.04s 2.15s
Bind Time 0.79s (± 0.70%) 0.79s (± 0.59%) -0.00s (- 0.25%) 0.78s 0.80s
Check Time 5.82s (± 0.66%) 5.82s (± 0.45%) -0.00s (- 0.09%) 5.77s 5.90s
Emit Time 6.17s (± 1.03%) 6.15s (± 0.93%) -0.02s (- 0.29%) 5.99s 6.28s
Total Time 14.83s (± 0.56%) 14.82s (± 0.52%) -0.01s (- 0.07%) 14.67s 15.04s
Compiler-Unions - node (v14.15.1, x64)
Memory used 192,632k (± 0.01%) 192,963k (± 0.38%) +331k (+ 0.17%) 192,603k 195,913k
Parse Time 0.85s (± 0.70%) 0.85s (± 0.40%) -0.01s (- 0.94%) 0.84s 0.85s
Bind Time 0.48s (± 0.77%) 0.49s (± 0.75%) +0.00s (+ 0.21%) 0.48s 0.49s
Check Time 6.67s (± 0.38%) 6.72s (± 0.65%) +0.05s (+ 0.70%) 6.64s 6.84s
Emit Time 2.41s (± 0.88%) 2.44s (± 1.18%) +0.04s (+ 1.45%) 2.40s 2.52s
Total Time 10.42s (± 0.40%) 10.49s (± 0.53%) +0.07s (+ 0.71%) 10.39s 10.64s
Monaco - node (v14.15.1, x64)
Memory used 326,520k (± 0.01%) 326,529k (± 0.01%) +9k (+ 0.00%) 326,448k 326,575k
Parse Time 1.56s (± 0.33%) 1.57s (± 0.49%) +0.00s (+ 0.26%) 1.55s 1.59s
Bind Time 0.72s (± 0.72%) 0.72s (± 0.80%) +0.00s (+ 0.28%) 0.71s 0.73s
Check Time 5.69s (± 0.47%) 5.75s (± 0.28%) +0.06s (+ 0.98%) 5.72s 5.79s
Emit Time 3.30s (± 0.54%) 3.35s (± 0.81%) +0.05s (+ 1.51%) 3.30s 3.44s
Total Time 11.29s (± 0.34%) 11.40s (± 0.32%) +0.11s (+ 0.99%) 11.30s 11.49s
TFS - node (v14.15.1, x64)
Memory used 289,651k (± 0.00%) 289,637k (± 0.01%) -15k (- 0.01%) 289,576k 289,672k
Parse Time 1.30s (± 0.76%) 1.30s (± 1.08%) 0.00s ( 0.00%) 1.28s 1.35s
Bind Time 0.79s (± 0.70%) 0.79s (± 1.60%) -0.00s (- 0.38%) 0.74s 0.80s
Check Time 5.33s (± 0.36%) 5.33s (± 0.30%) -0.01s (- 0.11%) 5.29s 5.36s
Emit Time 3.57s (± 0.58%) 3.58s (± 0.68%) +0.00s (+ 0.11%) 3.54s 3.65s
Total Time 11.00s (± 0.33%) 10.99s (± 0.34%) -0.01s (- 0.05%) 10.93s 11.09s
material-ui - node (v14.15.1, x64)
Memory used 438,119k (± 0.04%) 438,201k (± 0.01%) +83k (+ 0.02%) 438,118k 438,263k
Parse Time 1.85s (± 0.51%) 1.86s (± 0.54%) +0.01s (+ 0.32%) 1.84s 1.88s
Bind Time 0.58s (± 0.51%) 0.58s (± 0.84%) +0.01s (+ 1.04%) 0.57s 0.59s
Check Time 12.83s (± 0.48%) 12.82s (± 0.53%) -0.01s (- 0.08%) 12.70s 12.97s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.26s (± 0.41%) 15.26s (± 0.41%) -0.00s (- 0.01%) 15.15s 15.40s
xstate - node (v14.15.1, x64)
Memory used 547,419k (± 0.00%) 547,385k (± 0.00%) -33k (- 0.01%) 547,352k 547,428k
Parse Time 2.59s (± 0.36%) 2.59s (± 0.49%) +0.00s (+ 0.19%) 2.57s 2.63s
Bind Time 0.97s (± 0.89%) 0.97s (± 1.14%) -0.00s (- 0.10%) 0.93s 0.99s
Check Time 1.53s (± 0.54%) 1.54s (± 0.72%) +0.01s (+ 0.92%) 1.52s 1.57s
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) 0.00s ( 0.00%) 0.07s 0.07s
Total Time 5.16s (± 0.18%) 5.17s (± 0.35%) +0.01s (+ 0.25%) 5.14s 5.23s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 50553 10
Baseline main 10

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

Heya @ahejlsberg, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the top-repos suite comparing main and refs/pull/50553/merge:

Everything looks good!

@ahejlsberg
Copy link
Member Author

Tests are all clean and perf looks good. Ready to merge.

type NonNullableNew<T> = T & {};
type NonNullableOld<T> = T extends null | undefined ? never : T;

type IsNullWithoutStrictNullChecks = NonNullableNew<null>;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this name seems to be confusing to me since it doesn't actually describe the expected result (if I understand correctly) but rather it refers to what was a bug

@@ -0,0 +1,18 @@
// @strict: false
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be good to actually test these behaviors in both strict on and off.

Suggested change
// @strict: false
// @strict: true,false

Then rename the test to nonNullablesAndObjectIntersections.ts

@DanielRosenwasser
Copy link
Member

@typescript-bot perf test faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 31, 2022

Heya @DanielRosenwasser, I've started to run the abridged perf test suite on this PR at dd32cf8. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@DanielRosenwasser
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..50553

Metric main 50553 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 338,732k (± 0.00%) 338,740k (± 0.00%) +8k (+ 0.00%) 338,710k 338,766k
Parse Time 2.08s (± 1.37%) 2.10s (± 0.89%) +0.02s (+ 0.72%) 2.06s 2.16s
Bind Time 0.79s (± 0.38%) 0.80s (± 0.47%) +0.00s (+ 0.38%) 0.79s 0.80s
Check Time 5.82s (± 0.45%) 5.81s (± 0.39%) -0.01s (- 0.15%) 5.77s 5.86s
Emit Time 6.14s (± 0.63%) 6.17s (± 0.86%) +0.02s (+ 0.39%) 6.07s 6.29s
Total Time 14.84s (± 0.46%) 14.87s (± 0.49%) +0.03s (+ 0.23%) 14.70s 15.04s
Compiler-Unions - node (v14.15.1, x64)
Memory used 192,635k (± 0.01%) 192,645k (± 0.01%) +10k (+ 0.00%) 192,614k 192,688k
Parse Time 0.86s (± 0.78%) 0.86s (± 0.72%) +0.00s (+ 0.47%) 0.85s 0.87s
Bind Time 0.49s (± 0.91%) 0.49s (± 0.81%) +0.00s (+ 0.61%) 0.48s 0.50s
Check Time 6.69s (± 0.41%) 6.75s (± 0.37%) +0.06s (+ 0.91%) 6.71s 6.81s
Emit Time 2.39s (± 0.46%) 2.41s (± 1.09%) +0.02s (+ 0.84%) 2.35s 2.49s
Total Time 10.43s (± 0.28%) 10.52s (± 0.44%) +0.09s (+ 0.86%) 10.45s 10.66s
Monaco - node (v14.15.1, x64)
Memory used 326,520k (± 0.01%) 326,517k (± 0.01%) -3k (- 0.00%) 326,476k 326,579k
Parse Time 1.58s (± 0.64%) 1.59s (± 0.51%) +0.01s (+ 0.76%) 1.57s 1.61s
Bind Time 0.72s (± 0.77%) 0.73s (± 0.65%) +0.01s (+ 0.69%) 0.72s 0.74s
Check Time 5.72s (± 0.28%) 5.72s (± 0.50%) +0.00s (+ 0.07%) 5.65s 5.80s
Emit Time 3.32s (± 0.72%) 3.34s (± 0.60%) +0.02s (+ 0.66%) 3.28s 3.37s
Total Time 11.33s (± 0.25%) 11.38s (± 0.35%) +0.04s (+ 0.36%) 11.28s 11.45s
TFS - node (v14.15.1, x64)
Memory used 289,622k (± 0.01%) 289,643k (± 0.00%) +21k (+ 0.01%) 289,620k 289,669k
Parse Time 1.30s (± 0.73%) 1.31s (± 0.95%) +0.00s (+ 0.23%) 1.29s 1.35s
Bind Time 0.79s (± 0.78%) 0.79s (± 0.60%) +0.00s (+ 0.25%) 0.78s 0.80s
Check Time 5.34s (± 0.39%) 5.36s (± 0.43%) +0.01s (+ 0.26%) 5.29s 5.39s
Emit Time 3.60s (± 0.64%) 3.56s (± 1.19%) -0.03s (- 0.83%) 3.50s 3.66s
Total Time 11.03s (± 0.37%) 11.02s (± 0.46%) -0.01s (- 0.07%) 10.91s 11.14s
material-ui - node (v14.15.1, x64)
Memory used 438,198k (± 0.00%) 438,127k (± 0.04%) -71k (- 0.02%) 437,419k 438,239k
Parse Time 1.86s (± 0.40%) 1.87s (± 0.82%) +0.01s (+ 0.54%) 1.84s 1.91s
Bind Time 0.58s (± 0.82%) 0.58s (± 0.69%) -0.00s (- 0.69%) 0.57s 0.59s
Check Time 12.90s (± 0.52%) 12.94s (± 0.91%) +0.04s (+ 0.29%) 12.70s 13.26s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.34s (± 0.43%) 15.39s (± 0.81%) +0.04s (+ 0.29%) 15.15s 15.75s
xstate - node (v14.15.1, x64)
Memory used 547,392k (± 0.00%) 547,420k (± 0.00%) +29k (+ 0.01%) 547,365k 547,456k
Parse Time 2.60s (± 0.32%) 2.61s (± 0.54%) +0.01s (+ 0.50%) 2.59s 2.64s
Bind Time 0.97s (± 0.77%) 0.98s (± 0.74%) +0.01s (+ 0.51%) 0.96s 1.00s
Check Time 1.54s (± 0.54%) 1.54s (± 0.84%) +0.00s (+ 0.26%) 1.52s 1.57s
Emit Time 0.07s (± 3.14%) 0.07s (± 0.00%) -0.00s (- 1.41%) 0.07s 0.07s
Total Time 5.19s (± 0.30%) 5.21s (± 0.49%) +0.02s (+ 0.39%) 5.15s 5.26s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 50553 10
Baseline main 10

Developer Information:

Download Benchmark

@@ -15166,7 +15166,7 @@ namespace ts {
return includes & TypeFlags.IncludesWildcard ? wildcardType : anyType;
}
if (!strictNullChecks && includes & TypeFlags.Nullable) {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we try to delete this whole !strictNullChecks branch entirely? Or are you still fine with undefined & null being weirdly undefined in non-strict but never in strict?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need that check for cases where the intersection is a singleton null or undefined. undefined & null is already resolved to never by an earlier check.

Copy link
Member

@weswigham weswigham Aug 31, 2022

Choose a reason for hiding this comment

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

Oh, yeah, duh, I know why we can just delete this branch - 15 lines up there's a strictNullChecks only branch that does this already for strict mode - we can just delete both that strictNullChecks gate and this entire conditional.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, that branch also resolves null & object and null & { foo: string } to never, which we don't want to do in non-strictNullChecks mode.

Copy link
Member

Choose a reason for hiding this comment

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

But why not? If we're already adjusting null & {}, isn't that just a logical followup? null & {x} seems even more suspect than null & {}.

Copy link
Member Author

Choose a reason for hiding this comment

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

The whole premise of null and undefined being in the domain of every type is suspect. But that's non-strictNullChecks. My only objective here is to better align with pre-4.8 behavior in a corner case.

Copy link
Member

Choose a reason for hiding this comment

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

I would be open to seeing what happens and considering such a change for 4.9, but I think this workaround for 4.8 is okay for now.

@andrewbranch
Copy link
Member

@typescript-bot cherry-pick this to release-4.8

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 1, 2022

Heya @andrewbranch, I've started to run the task to cherry-pick this into release-4.8 on this PR at 4502553. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

Hey @andrewbranch, I've opened #50589 for you.

@andrewbranch
Copy link
Member

@ahejlsberg ready to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NonNullable<null> is null without strict null checks
7 participants