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

Make the falsy part of any/unknown any/unknown #39529

Merged
merged 1 commit into from
Aug 18, 2020

Conversation

andrewbranch
Copy link
Member

Fixes #39113

@RyanCavanaugh RyanCavanaugh added the Breaking Change Would introduce errors in existing code label Jul 9, 2020
@DanielRosenwasser
Copy link
Member

@typescript-bot pack this
@typescript-bot test this
@typescript-bot user test this
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 9, 2020

Heya @DanielRosenwasser, I've started to run the parallelized community code test suite on this PR at 485ef4e. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 9, 2020

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 9, 2020

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 9, 2020

Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 485ef4e. You can monitor the build here.

@DanielRosenwasser
Copy link
Member

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 9, 2020

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

Hey @DanielRosenwasser, 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/79343/artifacts?artifactName=tgz&fileId=11580E45091C4B21F61A807B1BB32B9BC97C37CF372C440FE37926688BB9942502&fileName=/typescript-4.0.0-insiders.20200709.tgz"
    }
}

and then running npm install.

@typescript-bot
Copy link
Collaborator

Hey @DanielRosenwasser, something went wrong when looking for the build artifact. (You can check the log here).

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@RyanCavanaugh
Copy link
Member

We're debating 4.0 vs 4.1 so please hold on merging for now

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..39529

Metric master 39529 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 343,939k (± 0.02%) 343,491k (± 0.02%) -448k (- 0.13%) 343,289k 343,611k
Parse Time 2.01s (± 0.58%) 2.01s (± 0.66%) +0.00s (+ 0.20%) 1.98s 2.04s
Bind Time 0.82s (± 0.84%) 0.81s (± 0.93%) -0.00s (- 0.12%) 0.80s 0.84s
Check Time 4.73s (± 0.37%) 4.75s (± 0.67%) +0.02s (+ 0.38%) 4.65s 4.82s
Emit Time 5.18s (± 0.46%) 5.17s (± 0.75%) -0.01s (- 0.12%) 5.10s 5.30s
Total Time 12.73s (± 0.24%) 12.74s (± 0.58%) +0.01s (+ 0.09%) 12.62s 12.93s
Monaco - node (v10.16.3, x64)
Memory used 339,142k (± 0.02%) 339,221k (± 0.03%) +80k (+ 0.02%) 339,015k 339,472k
Parse Time 1.59s (± 0.82%) 1.58s (± 0.53%) -0.01s (- 0.69%) 1.55s 1.59s
Bind Time 0.71s (± 0.56%) 0.71s (± 0.56%) 0.00s ( 0.00%) 0.70s 0.72s
Check Time 4.89s (± 0.73%) 4.88s (± 0.54%) -0.01s (- 0.12%) 4.83s 4.96s
Emit Time 2.77s (± 1.23%) 2.75s (± 1.33%) -0.02s (- 0.58%) 2.72s 2.89s
Total Time 9.96s (± 0.59%) 9.92s (± 0.52%) -0.03s (- 0.34%) 9.81s 10.05s
TFS - node (v10.16.3, x64)
Memory used 302,080k (± 0.02%) 302,038k (± 0.02%) -42k (- 0.01%) 301,898k 302,153k
Parse Time 1.22s (± 0.67%) 1.21s (± 0.89%) -0.01s (- 0.66%) 1.19s 1.23s
Bind Time 0.67s (± 1.09%) 0.67s (± 0.78%) +0.00s (+ 0.15%) 0.66s 0.68s
Check Time 4.40s (± 0.46%) 4.42s (± 0.41%) +0.02s (+ 0.57%) 4.38s 4.46s
Emit Time 2.89s (± 0.88%) 2.88s (± 0.97%) -0.01s (- 0.21%) 2.82s 2.94s
Total Time 9.17s (± 0.38%) 9.18s (± 0.38%) +0.02s (+ 0.19%) 9.12s 9.28s
material-ui - node (v10.16.3, x64)
Memory used 459,386k (± 0.01%) 459,122k (± 0.01%) -264k (- 0.06%) 458,928k 459,223k
Parse Time 2.04s (± 0.29%) 2.04s (± 0.46%) +0.00s (+ 0.20%) 2.02s 2.06s
Bind Time 0.65s (± 1.53%) 0.65s (± 1.56%) -0.00s (- 0.62%) 0.63s 0.68s
Check Time 12.88s (± 0.54%) 12.86s (± 0.51%) -0.02s (- 0.14%) 12.76s 13.06s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.57s (± 0.48%) 15.55s (± 0.42%) -0.02s (- 0.12%) 15.45s 15.74s
Angular - node (v12.1.0, x64)
Memory used 321,182k (± 0.03%) 320,630k (± 0.08%) -552k (- 0.17%) 319,617k 320,905k
Parse Time 1.99s (± 0.62%) 1.98s (± 0.79%) -0.01s (- 0.45%) 1.95s 2.02s
Bind Time 0.80s (± 0.69%) 0.80s (± 0.59%) +0.00s (+ 0.12%) 0.79s 0.81s
Check Time 4.62s (± 0.52%) 4.64s (± 0.72%) +0.03s (+ 0.56%) 4.57s 4.72s
Emit Time 5.35s (± 0.66%) 5.38s (± 0.85%) +0.03s (+ 0.64%) 5.31s 5.50s
Total Time 12.76s (± 0.40%) 12.81s (± 0.66%) +0.05s (+ 0.41%) 12.64s 13.00s
Monaco - node (v12.1.0, x64)
Memory used 321,547k (± 0.01%) 321,561k (± 0.01%) +14k (+ 0.00%) 321,396k 321,622k
Parse Time 1.55s (± 0.84%) 1.55s (± 0.69%) +0.00s (+ 0.26%) 1.52s 1.57s
Bind Time 0.69s (± 0.72%) 0.69s (± 0.68%) +0.00s (+ 0.58%) 0.68s 0.70s
Check Time 4.69s (± 0.62%) 4.67s (± 0.28%) -0.01s (- 0.32%) 4.64s 4.70s
Emit Time 2.81s (± 0.57%) 2.80s (± 0.74%) -0.01s (- 0.25%) 2.77s 2.85s
Total Time 9.73s (± 0.43%) 9.71s (± 0.39%) -0.01s (- 0.15%) 9.61s 9.81s
TFS - node (v12.1.0, x64)
Memory used 286,528k (± 0.02%) 286,560k (± 0.02%) +31k (+ 0.01%) 286,343k 286,647k
Parse Time 1.23s (± 0.76%) 1.24s (± 0.80%) +0.01s (+ 0.81%) 1.22s 1.26s
Bind Time 0.64s (± 1.04%) 0.64s (± 1.06%) +0.00s (+ 0.63%) 0.63s 0.66s
Check Time 4.30s (± 0.75%) 4.31s (± 0.31%) +0.00s (+ 0.09%) 4.28s 4.34s
Emit Time 2.90s (± 0.92%) 2.92s (± 0.70%) +0.02s (+ 0.72%) 2.88s 2.98s
Total Time 9.07s (± 0.54%) 9.11s (± 0.35%) +0.04s (+ 0.39%) 9.05s 9.19s
material-ui - node (v12.1.0, x64)
Memory used 437,515k (± 0.08%) 437,534k (± 0.02%) +19k (+ 0.00%) 437,319k 437,620k
Parse Time 2.03s (± 0.68%) 2.03s (± 0.49%) +0.00s (+ 0.05%) 2.00s 2.05s
Bind Time 0.63s (± 1.22%) 0.62s (± 1.21%) -0.00s (- 0.16%) 0.61s 0.64s
Check Time 11.63s (± 1.00%) 11.54s (± 0.87%) -0.09s (- 0.75%) 11.39s 11.78s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 14.28s (± 0.79%) 14.19s (± 0.70%) -0.08s (- 0.59%) 14.06s 14.44s
Angular - node (v8.9.0, x64)
Memory used 340,454k (± 0.01%) 340,105k (± 0.02%) -349k (- 0.10%) 339,968k 340,227k
Parse Time 2.54s (± 0.43%) 2.53s (± 0.54%) -0.01s (- 0.24%) 2.51s 2.56s
Bind Time 0.85s (± 1.60%) 0.85s (± 0.56%) +0.00s (+ 0.12%) 0.84s 0.86s
Check Time 5.35s (± 0.51%) 5.36s (± 0.50%) +0.01s (+ 0.22%) 5.30s 5.41s
Emit Time 5.92s (± 1.02%) 5.96s (± 0.69%) +0.04s (+ 0.61%) 5.86s 6.04s
Total Time 14.66s (± 0.53%) 14.70s (± 0.24%) +0.04s (+ 0.28%) 14.62s 14.78s
Monaco - node (v8.9.0, x64)
Memory used 340,465k (± 0.02%) 340,516k (± 0.01%) +51k (+ 0.02%) 340,424k 340,607k
Parse Time 1.88s (± 0.41%) 1.87s (± 0.62%) -0.00s (- 0.05%) 1.86s 1.91s
Bind Time 0.88s (± 0.86%) 0.88s (± 0.39%) -0.00s (- 0.11%) 0.88s 0.89s
Check Time 5.41s (± 0.42%) 5.41s (± 0.65%) +0.00s (+ 0.04%) 5.33s 5.50s
Emit Time 3.24s (± 0.90%) 3.22s (± 0.49%) -0.02s (- 0.71%) 3.18s 3.25s
Total Time 11.41s (± 0.40%) 11.39s (± 0.36%) -0.02s (- 0.18%) 11.30s 11.51s
TFS - node (v8.9.0, x64)
Memory used 303,847k (± 0.02%) 303,824k (± 0.01%) -23k (- 0.01%) 303,734k 303,926k
Parse Time 1.54s (± 0.46%) 1.54s (± 0.55%) +0.00s (+ 0.13%) 1.53s 1.56s
Bind Time 0.67s (± 0.70%) 0.67s (± 1.00%) -0.00s (- 0.45%) 0.65s 0.68s
Check Time 5.06s (± 1.21%) 4.98s (± 1.26%) -0.08s (- 1.52%) 4.91s 5.16s
Emit Time 2.99s (± 2.76%) 3.10s (± 2.65%) +0.11s (+ 3.68%) 2.88s 3.23s
Total Time 10.26s (± 0.41%) 10.29s (± 0.38%) +0.03s (+ 0.28%) 10.22s 10.39s
material-ui - node (v8.9.0, x64)
Memory used 463,623k (± 0.01%) 463,463k (± 0.01%) -160k (- 0.03%) 463,365k 463,556k
Parse Time 2.39s (± 0.64%) 2.38s (± 0.38%) -0.01s (- 0.25%) 2.37s 2.40s
Bind Time 0.78s (± 1.13%) 0.77s (± 1.36%) -0.00s (- 0.51%) 0.75s 0.79s
Check Time 17.18s (± 1.31%) 17.13s (± 0.64%) -0.05s (- 0.28%) 16.86s 17.39s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 20.34s (± 1.15%) 20.29s (± 0.57%) -0.05s (- 0.27%) 19.99s 20.57s
Angular - node (v8.9.0, x86)
Memory used 195,293k (± 0.01%) 195,125k (± 0.03%) -167k (- 0.09%) 195,051k 195,365k
Parse Time 2.45s (± 0.71%) 2.46s (± 1.13%) +0.01s (+ 0.45%) 2.42s 2.55s
Bind Time 0.99s (± 0.67%) 0.99s (± 0.53%) -0.00s (- 0.10%) 0.98s 1.00s
Check Time 4.83s (± 0.71%) 4.83s (± 0.53%) 0.00s ( 0.00%) 4.76s 4.88s
Emit Time 5.91s (± 0.94%) 5.89s (± 1.00%) -0.03s (- 0.42%) 5.73s 6.00s
Total Time 14.18s (± 0.44%) 14.17s (± 0.58%) -0.01s (- 0.08%) 13.92s 14.35s
Monaco - node (v8.9.0, x86)
Memory used 193,481k (± 0.02%) 193,491k (± 0.02%) +11k (+ 0.01%) 193,422k 193,638k
Parse Time 1.91s (± 0.82%) 1.91s (± 0.82%) +0.00s (+ 0.16%) 1.89s 1.96s
Bind Time 0.70s (± 0.95%) 0.70s (± 0.82%) -0.00s (- 0.43%) 0.69s 0.72s
Check Time 5.49s (± 0.49%) 5.49s (± 0.39%) -0.00s (- 0.04%) 5.44s 5.53s
Emit Time 2.67s (± 0.88%) 2.67s (± 0.75%) 0.00s ( 0.00%) 2.63s 2.72s
Total Time 10.78s (± 0.50%) 10.78s (± 0.30%) 0.00s ( 0.00%) 10.71s 10.87s
TFS - node (v8.9.0, x86)
Memory used 173,760k (± 0.04%) 173,755k (± 0.03%) -5k (- 0.00%) 173,674k 173,909k
Parse Time 1.60s (± 1.18%) 1.60s (± 1.20%) -0.00s (- 0.06%) 1.56s 1.64s
Bind Time 0.64s (± 0.70%) 0.64s (± 0.53%) -0.00s (- 0.16%) 0.63s 0.64s
Check Time 4.65s (± 0.61%) 4.67s (± 0.67%) +0.02s (+ 0.41%) 4.63s 4.77s
Emit Time 2.77s (± 0.56%) 2.78s (± 0.80%) +0.01s (+ 0.54%) 2.72s 2.84s
Total Time 9.65s (± 0.33%) 9.69s (± 0.34%) +0.03s (+ 0.32%) 9.62s 9.77s
material-ui - node (v8.9.0, x86)
Memory used 262,597k (± 0.00%) 262,395k (± 0.02%) -203k (- 0.08%) 262,295k 262,495k
Parse Time 2.46s (± 0.60%) 2.44s (± 0.38%) -0.02s (- 0.97%) 2.42s 2.46s
Bind Time 0.67s (± 0.90%) 0.67s (± 1.09%) +0.00s (+ 0.45%) 0.65s 0.68s
Check Time 15.75s (± 0.83%) 15.75s (± 0.58%) -0.00s (- 0.02%) 15.50s 15.95s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 18.88s (± 0.66%) 18.85s (± 0.48%) -0.03s (- 0.14%) 18.62s 19.05s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v8.9.0, x64)
  • node (v8.9.0, x86)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v8.9.0, x64)
  • material-ui - node (v8.9.0, x86)
Benchmark Name Iterations
Current 39529 10
Baseline master 10

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jul 9, 2020

Perf numbers seem reasonable, but someone should take another look.

Office UI Fabric seems to have some existing issues I can't tease out.

Here's a few user test changes

Uglify had type differences

https://github.com/typescript-bot/TypeScript/pull/58/files#diff-515e686b9c133473b3091193f6519572L138

- node_modules/uglify-js/lib/compress.js(6307,25): error TS2403: Subsequent variable declarations must have the same type.  Variable 'code' must be of type 'string', but here has type '{ get: () => string; toString: () => string; indent: (half: any) => void; indentation: () => number; current_width: () => number; should_break: () => boolean; has_parens: () => boolean; newline: () => void; print: (str: any) => void; ... 23 more ...; parent: (n: any) => any; }'.
+ node_modules/uglify-js/lib/compress.js(6307,25): error TS2403: Subsequent variable declarations must have the same type.  Variable 'code' must be of type 'string', but here has type '{ get: () => string; toString: () => string; indent: (half: any) => void; indentation: () => number; current_width: () => number; should_break: () => any; has_parens: () => boolean; newline: () => void; print: (str: any) => void; ... 23 more ...; parent: (n: any) => any; }'.

That's sort of expected I suppose.


https://github.com/typescript-bot/TypeScript/pull/58/files#diff-515e686b9c133473b3091193f6519572L150

- node_modules/uglify-js/lib/compress.js(7635,29): error TS2367: This condition will always return 'false' since the types 'boolean' and 'string' have no overlap.

This one seems questionable, but I can't figure out what the file looked like at that point.


VS Code had some breaks though:

https://github.com/typescript-bot/TypeScript/pull/58/files#diff-0e62d568d28b82cee9e66b2b8fafd290R7-R12

+ [XX:XX:XX] Error: /vscode/src/vs/platform/workspace/common/workspace.ts(85,3): Type 'unknown' is not assignable to type 'boolean'.
+ [XX:XX:XX] Error: /vscode/src/vs/platform/workspace/common/workspace.ts(130,3): Type 'unknown' is not assignable to type 'boolean'.
+ [XX:XX:XX] Error: /vscode/src/vs/workbench/common/editor/editorGroup.ts(53,2): Type 'unknown' is not assignable to type 'boolean'.
+ [XX:XX:XX] Error: /vscode/src/vs/platform/workspace/common/workspace.ts(85,3): Type 'unknown' is not assignable to type 'boolean'.
+ [XX:XX:XX] Error: /vscode/src/vs/platform/workspace/common/workspace.ts(130,3): Type 'unknown' is not assignable to type 'boolean'.
+ [XX:XX:XX] Error: /vscode/src/vs/workbench/common/editor/editorGroup.ts(53,2): Type 'unknown' is not assignable to type 'boolean'.

Note there are really 3 breaks, I'm not sure why the diff repeats itself. Some of these are technically correct. Kind of an obvious pattern around defining type predicates.

https://github.com/microsoft/vscode/blob/182db07de2745fe3a6369f4ad80ae930e006a99b/src/vs/workbench/common/editor/editorGroup.ts#L50-L54

https://github.com/microsoft/vscode/blob/182db07de2745fe3a6369f4ad80ae930e006a99b/src/vs/platform/workspace/common/workspace.ts#L84-L87

https://github.com/microsoft/vscode/blob/182db07de2745fe3a6369f4ad80ae930e006a99b/src/vs/platform/workspace/common/workspace.ts#L129-L134

@andrewbranch
Copy link
Member Author

andrewbranch commented Jul 9, 2020

I think the VS Code ones are good breaks. It’s not unique to type predicates, though they may be a common manifestation since the input is usually any or unknown. You’d get the same error if the return type was just boolean:

function isThing(x: any): boolean {
    return x && typeof x === 'object' && x.blah === 'foo';
}

This passes checking today but shouldn’t, since the actual domain of the return expression includes "", 0, null, and undefined. Savvy users already know to deal with this kind of error by prefixing the first x with !!, since you’d have to do that if the input type included falsy components but wasn’t any or unknown:

function isThing(x: string | number | Record<string, any>): boolean {
    return x && typeof x === 'object' && x.blah === 'foo';
    // Type 'boolean | "" | 0' is not assignable to type 'boolean'.
    //   Type '""' is not assignable to type 'boolean'.(2322)
}

[Playground]

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jul 9, 2020

Yeah, if you're using unknown, I think you sort of want to know about these breaks. If you're using any, well, you won't get a break in those cases.

@andrewbranch
Copy link
Member Author

I also don’t know how to see the uglify source either, but I can give you a simplified example of how this change would correctly remove that error you said looks questionable: playground

@DanielRosenwasser
Copy link
Member

(also, I don't know how to look at the other diffs, DevOps is too confusing)

@DanielRosenwasser
Copy link
Member

DefinitelyTyped tests

Error: /home/vsts/work/1/s/dtslint-runner/DefinitelyTyped/types/knockout/test/index.ts:710:5
ERROR: 710:5  expect  TypeScript@local expected type to be:
  KnockoutObservable<number>
got:
  KnockoutObservable<number | null>
Error: /home/vsts/work/1/s/dtslint-runner/DefinitelyTyped/types/testing-library__vue/testing-library__vue-tests.ts:69:21
ERROR: 69:21  expect  TypeScript@local compile error: 
Argument of type 'RegExp' is not assignable to parameter of type 'ARIARole'.
  Type 'RegExp' is not assignable to type '"alertdialog"'.
Subsequent property declarations must have the same type.  Property 'data' must be of type 'T | undefined', but here has type 'any'.
ERROR: 79:12  expect  TypeScript@local compile error: 
Subsequent property declarations must have the same type.  Property 'data' must be of type 'T', but here has type 'any'.
ERROR: 90:13  expect  TypeScript@local compile error: 
Subsequent variable declarations must have the same type.  Variable 'MessageEvent' must be of type '{ new <T>(type: string, eventInitDict?: MessageEventInit<T> | undefined): MessageEvent<T>; prototype: MessageEvent<any>; }', but here has type '{ new (type: string, eventInitDict?: MessageEventInit<any> | undefined): MessageEvent<any>; prototype: MessageEvent<any>; }'.

@DanielRosenwasser
Copy link
Member

I think RWC came back unaffected?

@andrewbranch
Copy link
Member Author

The DefinitelyTyped failures are all unrelated; they exist in the nightly dtslint run against master.

@orta
Copy link
Contributor

orta commented Jul 10, 2020

@typescript-bot pack this - playground build failed because it switched to the new repo and needed access - microsoft/TypeScript-Website#130 (comment)

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 10, 2020

Heya @orta, I've started to run the tarball bundle task on this PR at 485ef4e. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 10, 2020

Hey @orta, 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/79457/artifacts?artifactName=tgz&fileId=BE3592789947A37CBA3D20B1BA11BB36BDBC85FB7F6FAF1475BD409CC34A767902&fileName=/typescript-4.0.0-insiders.20200710.tgz"
    }
}

and then running npm install.


There is also a playground for this build.

@andrewbranch
Copy link
Member Author

From design meeting:

  • Explore propagating a better assignability error for a falsy-unknown source
  • Merge in 4.1

@andrewbranch
Copy link
Member Author

Explore propagating a better assignability error for a falsy-unknown source

This turns out to be a little bit difficult for two reasons:

  1. Doing the right thing with falsyUnknownType in a union requires tracking more info about constituent types than we currently do. If you union a falsy unknown with other definitely falsy types, the result should be falsy unknown. Otherwise, it should just be unknown. We don’t currently compute falsy flags for union constituents so I’m concerned about what this could do to performance.

  2. Even if we successfully propagate the falsy unknown type, I think a specialized error message isn’t very useful without being able to identify where the falsy unknown came from, and I’m not sure how best to walk back to that point. Example [playground]:

    function isThing(x: unknown): boolean {
      const result = x && typeof x === "object" && someOtherCriteria(x);
      return anotherCondition() ? result : false;
    }

    Ideally, you want the error elaboration / related info to highlight the x in x && typeof x ..., and I’m not sure the best way to propagate that through to or walk back from the assignability check.

@andrewbranch
Copy link
Member Author

Talked to @RyanCavanaugh and decided to merge this now—there may be no worthwhile way to track the falsy unknown back to the expression where it originated, and it’s better to get this in 4.1 sooner rather than later.

@andrewbranch andrewbranch merged commit dbab46c into microsoft:master Aug 18, 2020
@andrewbranch andrewbranch deleted the bug/39113 branch August 18, 2020 18:06
@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Aug 18, 2020
@DanielRosenwasser
Copy link
Member

@andrewbranch
Copy link
Member Author

Done 👍

@DanielRosenwasser
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team Breaking Change Would introduce errors in existing code 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.

Using && with spread operator causes "overridden" error if one of the types is "any"
5 participants