GeezerVison is showing github.com — [ID-Prep] PR3 - Preserve parameter types for optional parameters /fields with undefined in type and for required params with default value by dragomirtitian · Pull Request #57484 · microsoft/TypeScript
Conversation
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
robpalme and nicojs reacted with hooray emoji
|
|
if (!getParseTreeNode(node)) {
|
|
|
return type ? visitNode(type, visitDeclarationSubtree, isTypeNode) : factory.createKeywordTypeNode(SyntaxKind.AnyKeyword);
|
|
|
}
|
|
|
if (node.kind === SyntaxKind.SetAccessor) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ensureType is never called with a SetAccessorDeclaration. The set accessor type does not have a return type and the parameter type is inferred independently. Removing this had 0 impact on tests.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
-772
to
-773
|
|
if (isPropertySignature(node) || !node.initializer) return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker, shouldUseResolverType));
|
|
|
return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker, shouldUseResolverType) || resolver.createTypeOfExpression(node.initializer, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker));
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here is overly complicated. Both calls to createTypeOfDeclaration boil down to the same arguments. Also I have not found a test that benefits from the use of createTypeOfExpression on the initializer and I can't think of a case when this would help. (There might be some error case, but it's not tested for and returning any for that seems just as appropriate.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
default:
|
|
|
Debug.assertNever(node);
|
|
|
}
|
|
|
return cleanup(resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker));
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the cleanup closure. Since the logic is simpler now it's easier to just assign a variable and do the same cleanup after the switch.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined;
|
|
|
isRequiredInitializedParameter(node: ParameterDeclaration): boolean;
|
|
|
isOptionalUninitializedParameterProperty(node: ParameterDeclaration): boolean;
|
|
|
requiresAddingImplicitUndefined(node: ParameterDeclaration): boolean;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isRequiredInitializedParameter and isOptionalUninitializedParameterProperty were used only once in the declaration transform in (resolver.isRequiredInitializedParameter(node) || resolver.isOptionalUninitializedParameterProperty(node)). I think it's worth simplifying the API and only expose a function taht tells us is the parameter requires adding an implcit undefined to it's type or not.
requiresAddingImplicitUndefined also takes into account if the type already contains undefined and thus avoids re-printing types unless it's absolutely necessary. (Fixing #57483)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Hey Jake Bailey (@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/160079/artifacts?artifactName=tgz&fileId=FDE817C914166D03968B5E61E6C598FC243A028DFB51618D74A8AD63A70D275E02&fileName=/typescript-5.5.0-insiders.20240227.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/[email protected]".;
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Jake Bailey (@jakebailey) Here are the results of running the user test suite comparing main and refs/pull/57484/merge:
There were infrastructure failures potentially unrelated to your change:
- 1 instance of "Package install failed"
Otherwise...
Something interesting changed - please have a look.
Details
- [MISSING]
error TS2307: Cannot find module '@pptr/testserver' or its corresponding type declarations.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Jake Bailey (@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,668k (± 0.01%) |
295,691k (± 0.01%) |
~ |
295,656k |
295,749k |
p=0.575 n=6 |
| Parse Time |
2.67s (± 0.39%) |
2.67s (± 0.21%) |
~ |
2.66s |
2.67s |
p=0.663 n=6 |
| Bind Time |
0.83s (± 0.91%) |
0.83s (± 1.47%) |
~ |
0.82s |
0.85s |
p=0.388 n=6 |
| Check Time |
8.26s (± 0.29%) |
8.25s (± 0.25%) |
~ |
8.23s |
8.28s |
p=0.742 n=6 |
| Emit Time |
7.10s (± 0.42%) |
7.12s (± 0.54%) |
~ |
7.07s |
7.18s |
p=0.374 n=6 |
| Total Time |
18.85s (± 0.22%) |
18.86s (± 0.17%) |
~ |
18.83s |
18.92s |
p=0.329 n=6 |
| Compiler-Unions - node (v18.15.0, x64) |
| Memory used |
194,503k (± 1.64%) |
195,438k (± 1.53%) |
~ |
191,581k |
197,383k |
p=0.936 n=6 |
| Parse Time |
1.35s (± 1.48%) |
1.36s (± 1.14%) |
~ |
1.35s |
1.39s |
p=1.000 n=6 |
| Bind Time |
0.72s (± 0.00%) |
0.72s (± 0.00%) |
~ |
0.72s |
0.72s |
p=1.000 n=6 |
| Check Time |
9.34s (± 0.13%) |
9.35s (± 0.13%) |
~ |
9.34s |
9.37s |
p=0.061 n=6 |
| Emit Time |
2.60s (± 0.53%) |
2.61s (± 0.64%) |
~ |
2.59s |
2.63s |
p=0.618 n=6 |
| Total Time |
14.01s (± 0.20%) |
14.05s (± 0.09%) |
+0.04s (+ 0.25%) |
14.03s |
14.06s |
p=0.032 n=6 |
| Monaco - node (v18.15.0, x64) |
| Memory used |
347,475k (± 0.01%) |
347,475k (± 0.00%) |
~ |
347,451k |
347,498k |
p=1.000 n=6 |
| Parse Time |
2.48s (± 0.57%) |
2.48s (± 0.59%) |
~ |
2.46s |
2.50s |
p=0.870 n=6 |
| Bind Time |
0.93s (± 0.44%) |
0.93s (± 0.44%) |
~ |
0.92s |
0.93s |
p=1.000 n=6 |
| Check Time |
6.96s (± 0.38%) |
6.94s (± 0.20%) |
~ |
6.92s |
6.96s |
p=0.157 n=6 |
| Emit Time |
4.05s (± 0.52%) |
4.07s (± 0.40%) |
~ |
4.04s |
4.08s |
p=0.222 n=6 |
| Total Time |
14.42s (± 0.23%) |
14.41s (± 0.11%) |
~ |
14.39s |
14.43s |
p=0.806 n=6 |
| TFS - node (v18.15.0, x64) |
| Memory used |
302,874k (± 0.01%) |
302,877k (± 0.01%) |
~ |
302,846k |
302,939k |
p=0.936 n=6 |
| Parse Time |
2.02s (± 0.85%) |
2.01s (± 0.80%) |
~ |
1.99s |
2.03s |
p=0.415 n=6 |
| Bind Time |
1.00s (± 0.41%) |
1.00s (± 0.81%) |
~ |
1.00s |
1.02s |
p=1.000 n=6 |
| Check Time |
6.35s (± 0.53%) |
6.36s (± 0.33%) |
~ |
6.34s |
6.39s |
p=0.468 n=6 |
| Emit Time |
3.60s (± 0.45%) |
3.59s (± 0.82%) |
~ |
3.56s |
3.64s |
p=0.420 n=6 |
| Total Time |
12.97s (± 0.34%) |
12.97s (± 0.34%) |
~ |
12.92s |
13.05s |
p=0.936 n=6 |
| material-ui - node (v18.15.0, x64) |
| Memory used |
511,295k (± 0.01%) |
511,308k (± 0.01%) |
~ |
511,268k |
511,382k |
p=0.471 n=6 |
| Parse Time |
2.65s (± 0.65%) |
2.65s (± 0.39%) |
~ |
2.63s |
2.66s |
p=0.870 n=6 |
| Bind Time |
0.99s (± 0.99%) |
0.99s (± 1.04%) |
~ |
0.98s |
1.01s |
p=0.591 n=6 |
| Check Time |
17.23s (± 0.61%) |
17.26s (± 0.35%) |
~ |
17.16s |
17.34s |
p=0.423 n=6 |
| Emit Time |
0.00s (± 0.00%) |
0.00s (± 0.00%) |
~ |
0.00s |
0.00s |
p=1.000 n=6 |
| Total Time |
20.86s (± 0.54%) |
20.91s (± 0.30%) |
~ |
20.80s |
20.98s |
p=0.296 n=6 |
| mui-docs - node (v18.15.0, x64) |
| Memory used |
2,294,976k (± 0.00%) |
2,294,985k (± 0.00%) |
~ |
2,294,928k |
2,295,033k |
p=1.000 n=6 |
| Parse Time |
11.97s (± 0.93%) |
12.13s (± 1.64%) |
~ |
11.86s |
12.36s |
p=0.147 n=6 |
| Bind Time |
2.64s (± 0.83%) |
2.65s (± 0.21%) |
~ |
2.64s |
2.65s |
p=0.866 n=6 |
| Check Time |
102.00s (± 0.78%) |
101.98s (± 0.69%) |
~ |
100.80s |
102.64s |
p=0.936 n=6 |
| Emit Time |
0.32s (± 0.00%) |
0.32s (± 0.00%) |
~ |
0.32s |
0.32s |
p=1.000 n=6 |
| Total Time |
116.93s (± 0.66%) |
117.06s (± 0.56%) |
~ |
115.84s |
117.62s |
p=0.575 n=6 |
| self-build-src - node (v18.15.0, x64) |
| Memory used |
2,406,587k (± 0.02%) |
2,406,502k (± 0.01%) |
~ |
2,406,313k |
2,406,706k |
p=0.810 n=6 |
| Parse Time |
5.08s (± 0.69%) |
5.09s (± 0.86%) |
~ |
5.01s |
5.13s |
p=0.936 n=6 |
| Bind Time |
1.88s (± 0.48%) |
1.88s (± 0.52%) |
~ |
1.87s |
1.90s |
p=0.931 n=6 |
| Check Time |
33.63s (± 0.33%) |
33.74s (± 0.25%) |
~ |
33.64s |
33.88s |
p=0.093 n=6 |
| Emit Time |
2.66s (± 1.55%) |
2.71s (± 1.25%) |
~ |
2.67s |
2.76s |
p=0.127 n=6 |
| Total Time |
43.26s (± 0.26%) |
43.44s (± 0.09%) |
+0.17s (+ 0.40%) |
43.38s |
43.48s |
p=0.013 n=6 |
| self-compiler - node (v18.15.0, x64) |
| Memory used |
419,234k (± 0.01%) |
419,191k (± 0.01%) |
~ |
419,143k |
419,253k |
p=0.092 n=6 |
| Parse Time |
2.81s (± 0.57%) |
2.84s (± 0.62%) |
+0.03s (+ 1.01%) |
2.82s |
2.87s |
p=0.009 n=6 |
| Bind Time |
1.07s (± 0.70%) |
1.07s (± 0.48%) |
~ |
1.07s |
1.08s |
p=0.784 n=6 |
| Check Time |
15.23s (± 0.43%) |
15.24s (± 0.37%) |
~ |
15.15s |
15.30s |
p=0.808 n=6 |
| Emit Time |
1.14s (± 1.47%) |
1.15s (± 1.23%) |
~ |
1.13s |
1.17s |
p=0.367 n=6 |
| Total Time |
20.25s (± 0.28%) |
20.30s (± 0.33%) |
~ |
20.20s |
20.38s |
p=0.261 n=6 |
| vscode - node (v18.15.0, x64) |
| Memory used |
2,849,904k (± 0.00%) |
2,849,911k (± 0.00%) |
~ |
2,849,845k |
2,849,971k |
p=0.810 n=6 |
| Parse Time |
10.77s (± 0.37%) |
10.73s (± 0.22%) |
~ |
10.70s |
10.76s |
p=0.107 n=6 |
| Bind Time |
3.44s (± 0.35%) |
3.44s (± 0.56%) |
~ |
3.42s |
3.47s |
p=0.797 n=6 |
| Check Time |
60.75s (± 0.18%) |
60.75s (± 0.59%) |
~ |
60.37s |
61.29s |
p=0.873 n=6 |
| Emit Time |
16.25s (± 0.46%) |
16.22s (± 0.65%) |
~ |
16.07s |
16.36s |
p=0.521 n=6 |
| Total Time |
91.20s (± 0.16%) |
91.13s (± 0.42%) |
~ |
90.68s |
91.81s |
p=0.521 n=6 |
| webpack - node (v18.15.0, x64) |
| Memory used |
397,092k (± 0.02%) |
397,071k (± 0.01%) |
~ |
397,011k |
397,131k |
p=1.000 n=6 |
| Parse Time |
3.13s (± 0.56%) |
3.14s (± 0.66%) |
~ |
3.13s |
3.18s |
p=0.459 n=6 |
| Bind Time |
1.39s (± 0.98%) |
1.39s (± 0.59%) |
~ |
1.38s |
1.40s |
p=0.933 n=6 |
| Check Time |
14.10s (± 0.23%) |
14.07s (± 0.38%) |
~ |
14.03s |
14.17s |
p=0.198 n=6 |
| Emit Time |
0.00s (± 0.00%) |
0.00s (± 0.00%) |
~ |
0.00s |
0.00s |
p=1.000 n=6 |
| Total Time |
18.62s (± 0.27%) |
18.61s (± 0.29%) |
~ |
18.56s |
18.69s |
p=0.747 n=6 |
| xstate - node (v18.15.0, x64) |
| Memory used |
513,428k (± 0.01%) |
513,444k (± 0.01%) |
~ |
513,382k |
513,514k |
p=0.689 n=6 |
| Parse Time |
3.28s (± 0.27%) |
3.28s (± 0.17%) |
~ |
3.27s |
3.28s |
p=0.341 n=6 |
| Bind Time |
1.54s (± 0.26%) |
1.54s (± 0.54%) |
~ |
1.54s |
1.56s |
p=0.527 n=6 |
| Check Time |
2.87s (± 0.68%) |
2.87s (± 0.72%) |
~ |
2.84s |
2.89s |
p=1.000 n=6 |
| Emit Time |
0.08s (± 0.00%) |
0.08s (± 0.00%) |
~ |
0.08s |
0.08s |
p=1.000 n=6 |
| Total Time |
7.78s (± 0.16%) |
7.78s (± 0.16%) |
~ |
7.76s |
7.79s |
p=1.000 n=6 |
System info unknown
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Jake Bailey (@jakebailey) Here are the results of running the top-repos suite comparing main and refs/pull/57484/merge:
Everything looks good!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM though I am surprised that no other baselines changed.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
To be clear, this doesn't actually fix #57483, though, right? As we don't have the follow-up to continue node reuse?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
To be clear, this doesn't actually fix #57483, though, right? As we don't have the follow-up to continue node reuse?
It reuses type nodes if we know they are correct (if they already contain undefined). This is better than the situation before where it never reused the declared type node (see test output before the change). A follow on PR can always reuse the type node and add | undefined even if the declared type already includes it.
|
jakebailey reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
To be clear, this doesn't actually fix #57483, though, right? As we don't have the follow-up to continue node reuse?
It reuses type nodes if we know they are correct (if they already contain undefined). This is better than the situation before where it never reused the declared type node (see test output before the change). A follow on PR can always reuse the type node and add | undefined even if the declared type already includes it.
Upon further reflection, adding | undefined to all types will be a problem. People might raise bugs because their types are not the same as written as the | undefined will be redundant in some cases. It also goes against the general idea that in isolated declarations we keep the types you write.
I think this PR gets us as close to what an external tool could reasonably emit. The cases where the type is resolved in the new tests will be errors under --isolatedDeclarations
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's pretty clear. I think this PR is positive then, in that we're increasing node reuse (and under isolated mode, the cases that don't have reuse are just going to be illegal anyway).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Titian Cernicova-Dragomir (dragomirtitian)
changed the title
Preserve parameter types for optional parameters /fields with undefined in type and for required params with default value
[ID-Prep] PR3 - Preserve parameter types for optional parameters /fields with undefined in type and for required params with default value
Mar 7, 2024
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|