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

Allow implicit undefined returns when the contextual union type contains it #57912

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

fixes #57840

@RyanCavanaugh triaged this as a bug here. I'm pretty sure that @ahejlsberg didn't want this to work this way though (as per the description of #53607 and the comment in tests that I had to touch here).

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Mar 22, 2024
@jakebailey
Copy link
Member

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

@typescript-bot perf test this faster
@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 22, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started 👀 Results
perf test this faster ✅ Started 👀 Results
pack this ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 22, 2024

Hey @jakebailey, 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/160694/artifacts?artifactName=tgz&fileId=976D886DEE8ACEEF241EF5A35B6FFC03FD3FAC6E83579B8581E469403D8E9E5002&fileName=/typescript-5.5.0-insiders.20240322.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.5.0-pr-57912-2".;

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.

There were interesting changes:

Branch only errors:

Package: nodes7
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/nodes7/nodes7-tests.ts
  62:1  error  TypeScript@local compile error: 
Unused '@ts-expect-error' directive  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.18_typescript@5.5.0-dev.20240322/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.18_typescript@5.5.0-dev.20240322/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests comparing main and refs/pull/57912/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,514k (± 0.01%) 295,515k (± 0.00%) ~ 295,503k 295,530k p=0.199 n=6
Parse Time 2.66s (± 0.61%) 2.67s (± 0.39%) ~ 2.65s 2.68s p=0.358 n=6
Bind Time 0.83s (± 0.66%) 0.83s (± 1.41%) ~ 0.82s 0.85s p=0.859 n=6
Check Time 8.19s (± 0.23%) 8.21s (± 0.31%) ~ 8.18s 8.25s p=0.226 n=6
Emit Time 7.05s (± 0.20%) 7.06s (± 0.45%) ~ 7.03s 7.12s p=1.000 n=6
Total Time 18.73s (± 0.14%) 18.76s (± 0.27%) ~ 18.72s 18.85s p=0.198 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 193,094k (± 0.94%) 193,656k (± 1.01%) ~ 191,845k 195,576k p=0.810 n=6
Parse Time 1.35s (± 2.64%) 1.36s (± 1.30%) ~ 1.33s 1.38s p=0.870 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.47s (± 0.68%) 9.46s (± 0.34%) ~ 9.41s 9.50s p=0.935 n=6
Emit Time 2.62s (± 0.51%) 2.62s (± 0.68%) ~ 2.59s 2.64s p=0.743 n=6
Total Time 14.15s (± 0.62%) 14.15s (± 0.23%) ~ 14.10s 14.19s p=1.000 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,377k (± 0.01%) 347,380k (± 0.01%) ~ 347,359k 347,417k p=0.810 n=6
Parse Time 2.48s (± 0.34%) 2.48s (± 0.59%) ~ 2.46s 2.50s p=0.867 n=6
Bind Time 0.92s (± 0.56%) 0.92s (± 0.59%) ~ 0.92s 0.93s p=0.640 n=6
Check Time 7.01s (± 0.42%) 7.00s (± 0.28%) ~ 6.98s 7.03s p=0.324 n=6
Emit Time 4.06s (± 0.43%) 4.06s (± 0.34%) ~ 4.04s 4.08s p=0.871 n=6
Total Time 14.49s (± 0.18%) 14.47s (± 0.19%) ~ 14.42s 14.49s p=0.681 n=6
TFS - node (v18.15.0, x64)
Memory used 302,689k (± 0.01%) 302,713k (± 0.01%) ~ 302,681k 302,754k p=0.093 n=6
Parse Time 2.44s (± 0.48%) 2.42s (± 0.89%) -0.03s (- 1.02%) 2.39s 2.44s p=0.034 n=6
Bind Time 1.20s (± 0.46%) 1.20s (± 1.47%) ~ 1.18s 1.23s p=0.322 n=6
Check Time 7.46s (± 0.30%) 7.45s (± 0.37%) ~ 7.42s 7.50s p=0.742 n=6
Emit Time 4.28s (± 0.58%) 4.29s (± 0.82%) ~ 4.24s 4.33s p=0.872 n=6
Total Time 15.37s (± 0.25%) 15.35s (± 0.37%) ~ 15.26s 15.43s p=0.627 n=6
material-ui - node (v18.15.0, x64)
Memory used 509,899k (± 0.00%) 509,899k (± 0.00%) ~ 509,885k 509,920k p=1.000 n=6
Parse Time 2.64s (± 0.56%) 2.65s (± 0.50%) ~ 2.63s 2.66s p=0.394 n=6
Bind Time 0.99s (± 0.76%) 0.98s (± 1.19%) ~ 0.96s 0.99s p=0.383 n=6
Check Time 17.22s (± 0.45%) 17.27s (± 0.71%) ~ 17.18s 17.50s p=0.520 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.85s (± 0.32%) 20.90s (± 0.65%) ~ 20.78s 21.15s p=0.747 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,737,546k (± 0.00%) 1,737,562k (± 0.00%) ~ 1,737,506k 1,737,594k p=0.378 n=6
Parse Time 7.76s (± 0.29%) 7.80s (± 0.59%) ~ 7.76s 7.88s p=0.122 n=6
Bind Time 2.79s (± 0.67%) 2.81s (± 1.18%) ~ 2.76s 2.86s p=0.373 n=6
Check Time 66.65s (± 0.38%) 66.61s (± 0.49%) ~ 66.14s 66.99s p=0.748 n=6
Emit Time 0.15s (± 3.53%) 0.15s (± 2.69%) ~ 0.15s 0.16s p=0.282 n=6
Total Time 77.36s (± 0.34%) 77.37s (± 0.39%) ~ 76.87s 77.72s p=1.000 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,394,576k (± 0.03%) 2,394,386k (± 0.02%) ~ 2,393,918k 2,394,850k p=0.378 n=6
Parse Time 6.05s (± 1.49%) 6.05s (± 0.44%) ~ 6.02s 6.08s p=0.575 n=6
Bind Time 2.26s (± 0.97%) 2.25s (± 0.96%) ~ 2.24s 2.29s p=0.931 n=6
Check Time 39.43s (± 0.22%) 39.48s (± 0.39%) ~ 39.29s 39.72s p=0.689 n=6
Emit Time 3.14s (± 1.17%) 3.13s (± 1.28%) ~ 3.09s 3.19s p=0.873 n=6
Total Time 50.89s (± 0.20%) 50.92s (± 0.29%) ~ 50.70s 51.13s p=0.630 n=6
self-compiler - node (v18.15.0, x64)
Memory used 415,193k (± 0.00%) 415,235k (± 0.01%) +42k (+ 0.01%) 415,187k 415,270k p=0.031 n=6
Parse Time 3.41s (± 1.15%) 3.40s (± 1.31%) ~ 3.34s 3.46s p=0.515 n=6
Bind Time 1.29s (± 0.94%) 1.28s (± 0.77%) ~ 1.27s 1.29s p=0.507 n=6
Check Time 18.07s (± 0.36%) 18.07s (± 0.34%) ~ 17.99s 18.16s p=0.936 n=6
Emit Time 1.34s (± 1.19%) 1.31s (± 1.04%) -0.03s (- 2.11%) 1.29s 1.33s p=0.015 n=6
Total Time 24.11s (± 0.35%) 24.07s (± 0.42%) ~ 23.97s 24.23s p=0.572 n=6
vscode - node (v18.15.0, x64)
Memory used 2,890,201k (± 0.00%) 2,890,195k (± 0.00%) ~ 2,890,082k 2,890,313k p=0.873 n=6
Parse Time 12.93s (± 0.52%) 12.93s (± 0.27%) ~ 12.88s 12.98s p=0.810 n=6
Bind Time 4.12s (± 0.42%) 4.12s (± 0.36%) ~ 4.11s 4.14s p=1.000 n=6
Check Time 71.71s (± 0.55%) 71.52s (± 0.37%) ~ 71.21s 71.86s p=0.378 n=6
Emit Time 19.44s (± 0.36%) 19.45s (± 0.52%) ~ 19.33s 19.62s p=1.000 n=6
Total Time 108.20s (± 0.44%) 108.03s (± 0.30%) ~ 107.72s 108.59s p=0.689 n=6
webpack - node (v18.15.0, x64)
Memory used 408,148k (± 0.01%) 408,114k (± 0.01%) ~ 408,077k 408,140k p=0.092 n=6
Parse Time 3.91s (± 0.53%) 3.90s (± 0.53%) ~ 3.87s 3.93s p=0.223 n=6
Bind Time 1.69s (± 0.61%) 1.67s (± 1.05%) ~ 1.66s 1.70s p=0.249 n=6
Check Time 16.73s (± 0.43%) 16.75s (± 0.41%) ~ 16.67s 16.86s p=0.748 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.34s (± 0.35%) 22.33s (± 0.31%) ~ 22.25s 22.43s p=0.936 n=6
xstate - node (v18.15.0, x64)
Memory used 513,082k (± 0.02%) 512,993k (± 0.02%) ~ 512,925k 513,136k p=0.066 n=6
Parse Time 3.95s (± 0.41%) 4.01s (± 4.24%) ~ 3.92s 4.35s p=0.746 n=6
Bind Time 1.86s (± 0.88%) 1.84s (± 0.74%) ~ 1.82s 1.86s p=0.085 n=6
Check Time 3.39s (± 0.86%) 3.36s (± 0.15%) ~ 3.36s 3.37s p=0.100 n=6
Emit Time 0.09s (± 4.62%) 0.09s (± 6.44%) ~ 0.08s 0.09s p=0.282 n=6
Total Time 9.27s (± 0.38%) 9.30s (± 1.74%) ~ 9.20s 9.62s p=0.336 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@RyanCavanaugh
Copy link
Member

I think there's a possible parsing ambiguity in the referenced comment

Note that this does not apply to functions with union return types that include undefined

Foo | (() => undefined) vs () => (Foo | undefined)

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos comparing main and refs/pull/57912/merge:

Everything looks good!

@Andarist
Copy link
Contributor Author

The single reported failure here comes from those lines here. We can quickly verify on this TS playground that the contextual type of this function is (name: string) => string | undefined. So it makes sense that the error went away with this PR.

@sandersn sandersn added this to Not started in PR Backlog Apr 2, 2024
…turn-contextual-union

# Conflicts:
#	tests/baselines/reference/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.types
#	tests/baselines/reference/inferenceDoesNotAddUndefinedOrNull.types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Not started
PR Backlog
  
Not started
Development

Successfully merging this pull request may close these issues.

Return type incorrectly inferred as void
4 participants