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

New definition for omit that should ensure the name Omit is preserved… #37608

Closed
wants to merge 5 commits into from

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Mar 25, 2020

… in declaration output

Fixes #34793

This definition is backwards compatible (thanks to the default), but the declaration output may not be backwards compatible with the lib from older versions of TS (since we'll emit a reference to Omit with 3 type arguments). We could try to clean that up (maybe do some work to elide trailing type arguments if they're equivalent to the defaults), or take this as-is.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

I don't think this will help people unless we have a general way to not print default arguments that weren't provided (or are equal to their parameter's default). Even then it will be confusing to have a non-functional third parameter showing up in quick info.

This reminds me of being confused by basic_string's "extra" type parameters in C++ as a kid. I don't want to foist that on future generations.

@@ -2,18 +2,18 @@
// Repro from #29067

function test<T extends { a: string }>(obj: T) {
>test : <T extends { a: string; }>(obj: T) => Pick<T, Exclude<keyof T, "a">> & { b: string; }
>test : <T extends { a: string; }>(obj: T) => Omit<T, "a", Exclude<keyof T, "a">> & { b: string; }
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 the self-generating third argument is at least as bad as converting Omit to its definition.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think it's worth investing in hiding that argument when it matches the default? (As it always should)

Copy link
Member

Choose a reason for hiding this comment

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

Well, it solves one problem -- reading the type -- but not the second problem: writing the type.

And if it applies everywhere, the mismatch might just be confusing. Actually, hiding any optional item entirely is likely to be confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I’d prefer #31205 (comment):

type Omit<T, K extends keyof any> = T extends unknown ? Pick<T, Exclude<keyof T, K>> : never;

@DanielRosenwasser
Copy link
Member

I already tried to make Omit its own type, but then we ran into #31190

Does this new implementation avoid that issue?

@weswigham
Copy link
Member Author

@DanielRosenwasser this version preserves modifiers, unlike yours, as the mapped type is homomorphic; the 3rd type parameter is used to ensure such.

@rbuckton
Copy link
Member

rbuckton commented Apr 3, 2020

I'm generally not a fan of using type parameter defaults as an ad-hoc mechanism to introduce in-situ type aliases as it clutters the declaration output and quickinfo. I still think we should introduce some mechanism for in-situ type aliases to address this, similar to a let..in expression, i.e.:

type Omit<T, K extends keyof any> = 
  type Keys = Exclude<keyof T, K> in
  {
    [P in Keys]: T[P];
  };

@sandersn sandersn added this to Not started in PR Backlog Apr 15, 2020
@sandersn sandersn added the For Milestone Bug PRs that fix a bug with a specific milestone label Apr 15, 2020
@sandersn sandersn moved this from Not started to Waiting on author in PR Backlog Apr 15, 2020
@sandersn
Copy link
Member

@weswigham do you want to discuss this more, or look for a variant solution? If not, I'd like to close this PR to keep the number of open PRs manageable.

@weswigham
Copy link
Member Author

Did we wanna discuss our preferred approach here? Extra syntax for local type aliases and better default type parameter elision could both be ways forward here.

@sandersn
Copy link
Member

@weswigham should we keep looking for fixes for this PR or close it?

src/lib/es5.d.ts Outdated Show resolved Hide resolved
weswigham and others added 3 commits October 22, 2020 14:50
Co-authored-by: ExE Boss <3889017+ExE-Boss@users.noreply.github.com>
@weswigham
Copy link
Member Author

@DanielRosenwasser @rbuckton @sandersn @ahejlsberg I've changed this to use the template form to preserve the alias, as suggested by @ExE-Boss. I had to make the tiniest change to templated mapped type comparisons to get the tests to pass, however.

@ExE-Boss
Copy link
Contributor

@weswigham
Looks like tests/cases/conformance/types/literal/templateLiteralTypes1.ts is failing because the errors baseline has changed: https://github.com/microsoft/TypeScript/pull/37608/checks?check_run_id=1295283520#step:7:99

@weswigham
Copy link
Member Author

I could swear c2f4d8a should have fixed that when I ran it locally...

@weswigham
Copy link
Member Author

Oh wait, that's a different test that I just didn't notice was failing locally. Heh. Hold on.

@weswigham
Copy link
Member Author

Fixed. Notable: Our linter breaks because

Error: D:\Github\TypeScript\src\lib\es5.d.ts:1485:18  Parsing error: ']' expected.

We might need to update eslint? Or wait until the RC is out with the template mapped types to get parsing support for them in the linter? I'm unsure what, exactly, needs to go out before it'll lint without error.

@DanielRosenwasser
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 22, 2020

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 22, 2020

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 22, 2020

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 22, 2020

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 22, 2020

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

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..37608

Metric master 37608 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 349,757k (± 0.02%) 350,665k (± 0.01%) +908k (+ 0.26%) 350,583k 350,761k
Parse Time 2.01s (± 0.80%) 2.00s (± 0.71%) -0.01s (- 0.40%) 1.98s 2.03s
Bind Time 0.82s (± 1.07%) 0.83s (± 0.78%) +0.01s (+ 0.61%) 0.82s 0.84s
Check Time 4.94s (± 0.54%) 5.41s (± 0.76%) +0.47s (+ 9.60%) 5.34s 5.50s
Emit Time 5.19s (± 0.41%) 5.24s (± 0.88%) +0.05s (+ 1.02%) 5.18s 5.38s
Total Time 12.96s (± 0.34%) 13.48s (± 0.62%) +0.52s (+ 4.03%) 13.33s 13.70s
Monaco - node (v10.16.3, x64)
Memory used 354,351k (± 0.02%) 354,519k (± 0.02%) +168k (+ 0.05%) 354,334k 354,717k
Parse Time 1.57s (± 0.57%) 1.57s (± 0.43%) +0.00s (+ 0.06%) 1.56s 1.58s
Bind Time 0.71s (± 0.56%) 0.72s (± 0.62%) +0.01s (+ 0.98%) 0.71s 0.73s
Check Time 5.07s (± 0.54%) 5.54s (± 0.38%) +0.47s (+ 9.23%) 5.50s 5.59s
Emit Time 2.76s (± 0.93%) 2.80s (± 0.91%) +0.04s (+ 1.34%) 2.75s 2.88s
Total Time 10.11s (± 0.37%) 10.62s (± 0.43%) +0.51s (+ 5.04%) 10.55s 10.72s
TFS - node (v10.16.3, x64)
Memory used 307,640k (± 0.04%) 307,844k (± 0.02%) +204k (+ 0.07%) 307,785k 308,008k
Parse Time 1.22s (± 0.76%) 1.21s (± 0.56%) -0.01s (- 0.65%) 1.20s 1.23s
Bind Time 0.66s (± 1.37%) 0.67s (± 0.54%) +0.01s (+ 1.97%) 0.67s 0.68s
Check Time 4.57s (± 0.94%) 5.05s (± 0.81%) +0.48s (+10.49%) 4.95s 5.13s
Emit Time 2.90s (± 1.72%) 2.90s (± 1.04%) -0.00s (- 0.07%) 2.82s 2.96s
Total Time 9.35s (± 0.59%) 9.83s (± 0.35%) +0.49s (+ 5.21%) 9.75s 9.91s
material-ui - node (v10.16.3, x64)
Memory used 489,125k (± 0.02%) 489,201k (± 0.01%) +76k (+ 0.02%) 489,127k 489,266k
Parse Time 1.99s (± 0.54%) 1.98s (± 0.50%) -0.01s (- 0.40%) 1.96s 2.00s
Bind Time 0.65s (± 0.90%) 0.65s (± 0.89%) +0.00s (+ 0.46%) 0.64s 0.66s
Check Time 13.42s (± 0.51%) 13.89s (± 0.71%) +0.47s (+ 3.49%) 13.68s 14.05s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.06s (± 0.45%) 16.53s (± 0.61%) +0.47s (+ 2.91%) 16.32s 16.69s
Angular - node (v12.1.0, x64)
Memory used 326,934k (± 0.02%) 327,802k (± 0.03%) +869k (+ 0.27%) 327,574k 327,979k
Parse Time 2.00s (± 0.53%) 2.01s (± 0.72%) +0.01s (+ 0.50%) 1.98s 2.04s
Bind Time 0.81s (± 1.12%) 0.81s (± 0.64%) +0.00s (+ 0.25%) 0.80s 0.82s
Check Time 4.83s (± 0.40%) 5.34s (± 0.62%) +0.51s (+10.51%) 5.28s 5.43s
Emit Time 5.39s (± 0.84%) 5.45s (± 0.63%) +0.06s (+ 1.04%) 5.35s 5.50s
Total Time 13.04s (± 0.52%) 13.62s (± 0.45%) +0.58s (+ 4.43%) 13.51s 13.77s
Monaco - node (v12.1.0, x64)
Memory used 336,578k (± 0.02%) 336,743k (± 0.02%) +165k (+ 0.05%) 336,623k 336,859k
Parse Time 1.54s (± 0.72%) 1.55s (± 1.06%) +0.01s (+ 0.85%) 1.52s 1.60s
Bind Time 0.69s (± 0.58%) 0.69s (± 0.49%) +0.00s (+ 0.58%) 0.69s 0.70s
Check Time 4.88s (± 0.50%) 5.40s (± 0.68%) +0.52s (+10.67%) 5.34s 5.51s
Emit Time 2.82s (± 0.91%) 2.85s (± 1.24%) +0.02s (+ 0.82%) 2.80s 2.97s
Total Time 9.93s (± 0.39%) 10.49s (± 0.67%) +0.56s (+ 5.64%) 10.40s 10.73s
TFS - node (v12.1.0, x64)
Memory used 291,933k (± 0.03%) 291,992k (± 0.02%) +58k (+ 0.02%) 291,874k 292,158k
Parse Time 1.23s (± 0.49%) 1.23s (± 0.57%) +0.00s (+ 0.33%) 1.22s 1.25s
Bind Time 0.65s (± 1.38%) 0.65s (± 0.93%) -0.00s (- 0.15%) 0.63s 0.66s
Check Time 4.47s (± 0.30%) 5.02s (± 0.61%) +0.55s (+12.36%) 4.95s 5.08s
Emit Time 2.92s (± 0.99%) 2.93s (± 0.86%) +0.01s (+ 0.24%) 2.85s 2.97s
Total Time 9.26s (± 0.36%) 9.82s (± 0.57%) +0.56s (+ 6.04%) 9.68s 9.93s
material-ui - node (v12.1.0, x64)
Memory used 467,034k (± 0.05%) 467,301k (± 0.02%) +267k (+ 0.06%) 467,163k 467,500k
Parse Time 2.01s (± 0.37%) 2.01s (± 0.38%) +0.00s (+ 0.05%) 2.00s 2.03s
Bind Time 0.64s (± 1.05%) 0.64s (± 0.97%) +0.00s (+ 0.31%) 0.63s 0.66s
Check Time 12.05s (± 0.94%) 12.52s (± 1.11%) +0.47s (+ 3.92%) 12.29s 12.83s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 14.70s (± 0.81%) 15.17s (± 0.95%) +0.47s (+ 3.20%) 14.94s 15.49s
Angular - node (v8.9.0, x64)
Memory used 346,442k (± 0.01%) 347,296k (± 0.02%) +854k (+ 0.25%) 347,210k 347,482k
Parse Time 2.54s (± 0.51%) 2.56s (± 0.29%) +0.02s (+ 0.59%) 2.55s 2.58s
Bind Time 0.85s (± 0.43%) 0.88s (± 0.78%) +0.02s (+ 2.46%) 0.86s 0.89s
Check Time 5.56s (± 0.52%) 6.00s (± 0.68%) +0.44s (+ 7.92%) 5.91s 6.07s
Emit Time 6.15s (± 1.07%) 6.24s (± 1.97%) +0.09s (+ 1.53%) 6.04s 6.54s
Total Time 15.11s (± 0.55%) 15.68s (± 0.90%) +0.57s (+ 3.77%) 15.41s 16.07s
Monaco - node (v8.9.0, x64)
Memory used 355,704k (± 0.02%) 355,830k (± 0.01%) +126k (+ 0.04%) 355,760k 355,978k
Parse Time 1.89s (± 0.77%) 1.89s (± 0.63%) +0.01s (+ 0.32%) 1.87s 1.93s
Bind Time 0.89s (± 0.45%) 0.89s (± 0.91%) -0.00s (- 0.11%) 0.88s 0.91s
Check Time 5.62s (± 0.37%) 6.26s (± 1.29%) +0.64s (+11.29%) 6.09s 6.36s
Emit Time 3.29s (± 1.17%) 3.01s (± 4.80%) 🟩-0.27s (- 8.37%) 2.86s 3.34s
Total Time 11.69s (± 0.28%) 12.05s (± 0.71%) +0.36s (+ 3.10%) 11.91s 12.26s
TFS - node (v8.9.0, x64)
Memory used 309,391k (± 0.02%) 309,437k (± 0.01%) +45k (+ 0.01%) 309,372k 309,525k
Parse Time 1.55s (± 0.64%) 1.56s (± 0.33%) +0.01s (+ 0.39%) 1.54s 1.57s
Bind Time 0.68s (± 0.73%) 0.68s (± 0.81%) +0.01s (+ 0.89%) 0.67s 0.69s
Check Time 5.31s (± 0.58%) 5.75s (± 0.41%) +0.44s (+ 8.29%) 5.71s 5.81s
Emit Time 2.94s (± 0.34%) 2.97s (± 0.94%) +0.03s (+ 1.09%) 2.90s 3.03s
Total Time 10.48s (± 0.34%) 10.96s (± 0.25%) +0.48s (+ 4.60%) 10.91s 11.04s
material-ui - node (v8.9.0, x64)
Memory used 493,431k (± 0.01%) 493,547k (± 0.01%) +116k (+ 0.02%) 493,461k 493,724k
Parse Time 2.40s (± 0.46%) 2.40s (± 0.43%) -0.00s (- 0.04%) 2.37s 2.42s
Bind Time 0.81s (± 1.02%) 0.82s (± 1.15%) +0.01s (+ 0.74%) 0.79s 0.84s
Check Time 17.95s (± 0.69%) 18.44s (± 0.90%) +0.48s (+ 2.70%) 18.05s 18.73s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 21.17s (± 0.56%) 21.66s (± 0.77%) +0.49s (+ 2.31%) 21.27s 21.94s
Angular - node (v8.9.0, x86)
Memory used 198,690k (± 0.01%) 199,149k (± 0.03%) +459k (+ 0.23%) 198,971k 199,277k
Parse Time 2.48s (± 1.02%) 2.48s (± 0.51%) +0.00s (+ 0.12%) 2.46s 2.51s
Bind Time 1.00s (± 1.00%) 1.01s (± 1.25%) +0.01s (+ 0.60%) 0.98s 1.05s
Check Time 5.05s (± 0.56%) 5.47s (± 0.42%) +0.42s (+ 8.36%) 5.40s 5.51s
Emit Time 5.89s (± 0.83%) 6.00s (± 1.22%) +0.12s (+ 1.95%) 5.84s 6.16s
Total Time 14.42s (± 0.58%) 14.96s (± 0.58%) +0.54s (+ 3.77%) 14.75s 15.10s
Monaco - node (v8.9.0, x86)
Memory used 201,493k (± 0.01%) 201,599k (± 0.02%) +106k (+ 0.05%) 201,498k 201,693k
Parse Time 1.94s (± 1.05%) 1.93s (± 0.63%) -0.02s (- 0.87%) 1.90s 1.96s
Bind Time 0.71s (± 0.47%) 0.71s (± 0.81%) 0.00s ( 0.00%) 0.70s 0.73s
Check Time 5.47s (± 0.38%) 6.20s (± 0.75%) +0.73s (+13.32%) 6.11s 6.30s
Emit Time 3.06s (± 0.59%) 2.73s (± 1.66%) 🟩-0.32s (-10.54%) 2.66s 2.89s
Total Time 11.18s (± 0.25%) 11.56s (± 0.69%) +0.39s (+ 3.46%) 11.43s 11.82s
TFS - node (v8.9.0, x86)
Memory used 176,867k (± 0.03%) 176,943k (± 0.02%) +75k (+ 0.04%) 176,877k 177,048k
Parse Time 1.60s (± 1.10%) 1.59s (± 0.55%) -0.02s (- 1.06%) 1.58s 1.62s
Bind Time 0.66s (± 2.04%) 0.64s (± 0.74%) -0.01s (- 1.83%) 0.63s 0.65s
Check Time 4.82s (± 0.58%) 5.31s (± 0.81%) +0.49s (+10.08%) 5.24s 5.45s
Emit Time 2.80s (± 0.66%) 2.80s (± 1.38%) -0.00s (- 0.18%) 2.74s 2.92s
Total Time 9.88s (± 0.51%) 10.34s (± 0.45%) +0.45s (+ 4.57%) 10.22s 10.42s
material-ui - node (v8.9.0, x86)
Memory used 277,878k (± 0.02%) 277,877k (± 0.02%) -1k (- 0.00%) 277,680k 277,959k
Parse Time 2.46s (± 0.43%) 2.47s (± 0.72%) +0.02s (+ 0.65%) 2.44s 2.53s
Bind Time 0.69s (± 1.35%) 0.74s (± 6.79%) +0.05s (+ 7.12%) 0.67s 0.89s
Check Time 16.45s (± 0.73%) 16.94s (± 0.84%) +0.49s (+ 2.99%) 16.72s 17.23s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 19.60s (± 0.63%) 20.15s (± 0.66%) +0.56s (+ 2.85%) 19.94s 20.43s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-generic
Architecturex64
Available Memory16 GB
Available Memory2 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 37608 10
Baseline master 10

@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.

@ExE-Boss
Copy link
Contributor

This should also have “Fixes #31104” in the PR description.

@weswigham
Copy link
Member Author

I'm gonna say this is superseded by #42524 now~

@weswigham weswigham closed this Jan 27, 2021
PR Backlog automation moved this from Waiting on author to Done Jan 27, 2021
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
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

Compiled .d.ts output for Omit is verbose and semantically inconsistent
6 participants