Skip to content

Improve contextually typed parameters with initializers #56506

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

Conversation

Andarist
Copy link
Contributor

fixes #56505

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 22, 2023
@Andarist Andarist changed the title Prefer the initializer type over contextual never parameter type Improve contextually typed parameters with initializers Nov 22, 2023
type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration, CheckMode.Normal));
if (type && declaration.initializer) {
const initializerType = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration, CheckMode.Normal));
if (!isTypeAssignableTo(initializerType, type) && isTypeAssignableTo(type, initializerType)) {

Choose a reason for hiding this comment

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

Hmm... what happens in the case of mutually assignable types?

Copy link
Contributor Author

@Andarist Andarist Nov 22, 2023

Choose a reason for hiding this comment

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

How many of them do we have? There is, of course, any and I can also think of bivariant methods but I can't call more on the spot.

That said - if the types are mutually assignable then the old behavior is preserved (the contextual parameter type is preferred). Can you think of any scenario in which this would be problematic?

Choose a reason for hiding this comment

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

I guess you’re right. If the types are mutually assignable then it probably doesn’t matter which one is picked and in the absence of a type annotation it makes more sense to pick the contextual type (especially since it prevents inferred anys from sneaking in)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

especially since it prevents inferred anys from sneaking in

That I'm not so sure about :p

const test: (arg: any) => void = (arg = 5) => {
  arg
  // ^? (parameter) arg: any
};

But inferring number would also not be good here either. It would only give the illusion of type-safety within the function while test would still be callable with just anything.

Copy link

@fatcerberus fatcerberus Nov 25, 2023

Choose a reason for hiding this comment

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

I specifically meant inferring any from a default when there’s a more sane contextual type available. That’d be really bad IMO.

@gabritto
Copy link
Member

gabritto commented Dec 2, 2023

@typescript-bot run DT
@typescript-bot user test this
@typescript-bot test top100
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 2, 2023

Heya @gabritto, I've started to run the regular perf test suite on this PR at aff1cfa. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 2, 2023

Heya @gabritto, I've started to run the diff-based top-repos suite on this PR at aff1cfa. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 2, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 2, 2023

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

Update: The results are in!

Copy link
Member

@gabritto gabritto left a comment

Choose a reason for hiding this comment

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

Looks right to me, let's wait on the tests.

@typescript-bot
Copy link
Collaborator

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

There were infrastructure failures potentially unrelated to your change:

  • 2 instances of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

puppeteer

packages/browsers/test/src/tsconfig.json

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,379k (± 0.00%) 295,375k (± 0.01%) ~ 295,351k 295,423k p=0.574 n=6
Parse Time 2.65s (± 0.19%) 2.65s (± 0.31%) ~ 2.64s 2.66s p=0.929 n=6
Bind Time 0.82s (± 0.00%) 0.82s (± 0.00%) ~ 0.82s 0.82s p=1.000 n=6
Check Time 8.14s (± 0.26%) 8.13s (± 0.25%) ~ 8.10s 8.16s p=0.808 n=6
Emit Time 7.08s (± 0.19%) 7.07s (± 0.19%) ~ 7.05s 7.09s p=0.317 n=6
Total Time 18.69s (± 0.15%) 18.68s (± 0.15%) ~ 18.64s 18.72s p=0.318 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 191,851k (± 0.54%) 195,267k (± 1.53%) ~ 191,386k 197,219k p=0.128 n=6
Parse Time 1.36s (± 1.27%) 1.36s (± 0.93%) ~ 1.34s 1.37s p=0.934 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.57%) ~ 0.72s 0.73s p=0.405 n=6
Check Time 9.26s (± 0.22%) 9.30s (± 0.37%) ~ 9.24s 9.34s p=0.086 n=6
Emit Time 2.61s (± 0.66%) 2.62s (± 0.74%) ~ 2.60s 2.65s p=0.415 n=6
Total Time 13.95s (± 0.33%) 14.00s (± 0.34%) ~ 13.94s 14.07s p=0.090 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,381k (± 0.01%) 347,371k (± 0.00%) ~ 347,361k 347,387k p=0.230 n=6
Parse Time 2.45s (± 0.56%) 2.46s (± 0.17%) ~ 2.45s 2.46s p=0.796 n=6
Bind Time 0.93s (± 0.81%) 0.92s (± 0.44%) ~ 0.92s 0.93s p=0.100 n=6
Check Time 6.90s (± 0.27%) 6.92s (± 0.30%) ~ 6.90s 6.96s p=0.157 n=6
Emit Time 4.05s (± 0.46%) 4.05s (± 0.51%) ~ 4.01s 4.07s p=1.000 n=6
Total Time 14.33s (± 0.19%) 14.35s (± 0.21%) ~ 14.31s 14.39s p=0.292 n=6
TFS - node (v18.15.0, x64)
Memory used 302,663k (± 0.00%) 302,662k (± 0.00%) ~ 302,649k 302,680k p=0.810 n=6
Parse Time 1.99s (± 0.59%) 1.99s (± 0.52%) ~ 1.97s 2.00s p=0.351 n=6
Bind Time 1.00s (± 1.17%) 1.00s (± 1.22%) ~ 0.99s 1.02s p=0.673 n=6
Check Time 6.29s (± 0.21%) 6.30s (± 0.53%) ~ 6.27s 6.35s p=1.000 n=6
Emit Time 3.57s (± 0.77%) 3.57s (± 0.65%) ~ 3.53s 3.59s p=0.677 n=6
Total Time 12.86s (± 0.27%) 12.86s (± 0.31%) ~ 12.78s 12.88s p=0.739 n=6
material-ui - node (v18.15.0, x64)
Memory used 506,731k (± 0.00%) 506,749k (± 0.01%) ~ 506,717k 506,799k p=0.630 n=6
Parse Time 2.59s (± 0.47%) 2.58s (± 0.62%) ~ 2.57s 2.61s p=0.209 n=6
Bind Time 0.99s (± 0.99%) 0.98s (± 1.24%) ~ 0.97s 1.00s p=0.601 n=6
Check Time 16.85s (± 0.47%) 16.89s (± 0.37%) ~ 16.83s 16.99s p=0.421 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.43s (± 0.47%) 20.45s (± 0.32%) ~ 20.40s 20.57s p=0.574 n=6
xstate - node (v18.15.0, x64)
Memory used 512,749k (± 0.01%) 512,709k (± 0.01%) ~ 512,638k 512,761k p=0.298 n=6
Parse Time 3.27s (± 0.23%) 3.27s (± 0.23%) ~ 3.26s 3.28s p=1.000 n=6
Bind Time 1.54s (± 0.49%) 1.54s (± 0.34%) ~ 1.53s 1.54s p=0.784 n=6
Check Time 2.81s (± 1.05%) 2.81s (± 0.27%) ~ 2.80s 2.82s p=0.331 n=6
Emit Time 0.08s (± 4.99%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=0.405 n=6
Total Time 7.69s (± 0.41%) 7.69s (± 0.16%) ~ 7.68s 7.71s p=0.686 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)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,350ms (± 0.60%) 2,343ms (± 0.20%) ~ 2,335ms 2,349ms p=0.630 n=6
Req 2 - geterr 5,405ms (± 1.41%) 5,368ms (± 0.33%) ~ 5,350ms 5,398ms p=1.000 n=6
Req 3 - references 324ms (± 1.48%) 324ms (± 1.23%) ~ 320ms 331ms p=1.000 n=6
Req 4 - navto 278ms (± 1.18%) 280ms (± 0.15%) ~ 279ms 280ms p=0.214 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 84ms (± 5.88%) 80ms (± 2.62%) ~ 76ms 82ms p=0.360 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,481ms (± 0.97%) 2,475ms (± 0.61%) ~ 2,463ms 2,496ms p=0.748 n=6
Req 2 - geterr 4,165ms (± 1.76%) 4,138ms (± 2.08%) ~ 4,041ms 4,225ms p=0.630 n=6
Req 3 - references 339ms (± 1.39%) 343ms (± 1.74%) ~ 335ms 348ms p=0.332 n=6
Req 4 - navto 286ms (± 1.08%) 285ms (± 0.41%) ~ 284ms 287ms p=0.508 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 81ms (± 7.79%) 85ms (± 6.74%) ~ 77ms 90ms p=0.461 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,602ms (± 0.71%) 2,601ms (± 0.49%) ~ 2,587ms 2,615ms p=0.747 n=6
Req 2 - geterr 1,699ms (± 2.00%) 1,718ms (± 2.58%) ~ 1,632ms 1,755ms p=0.173 n=6
Req 3 - references 107ms (± 8.01%) 114ms (± 8.96%) ~ 101ms 123ms p=0.572 n=6
Req 4 - navto 365ms (± 0.17%) 365ms (± 0.35%) ~ 363ms 367ms p=1.000 n=6
Req 5 - completionInfo count 2,073 (± 0.00%) 2,073 (± 0.00%) ~ 2,073 2,073 p=1.000 n=6
Req 5 - completionInfo 312ms (± 1.43%) 316ms (± 1.74%) ~ 308ms 322ms p=0.148 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 152.74ms (± 0.19%) 152.72ms (± 0.19%) ~ 151.70ms 156.18ms p=0.895 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 228.15ms (± 0.15%) 228.03ms (± 0.15%) -0.12ms (- 0.05%) 226.91ms 232.38ms p=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 229.68ms (± 0.17%) 229.93ms (± 0.82%) +0.25ms (+ 0.11%) 227.84ms 263.31ms p=0.000 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 229.12ms (± 0.19%) 229.13ms (± 0.19%) ~ 227.70ms 234.59ms p=0.828 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

Hey @gabritto, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Something interesting changed - please have a look.

Details

AykutSarac/jsoncrack.com

tsconfig.json

@Andarist
Copy link
Contributor Author

Andarist commented Dec 2, 2023

Minimal repro case for the above:

type CanvasDirection = "RIGHT" | "LEFT"
interface GraphActions {
  setDirection: (direction: CanvasDirection) => void;
}
declare function create<T>(config: T): void
create<GraphActions>({
  setDirection: (direction = "RIGHT") => {
    direction // should be `CanvasDirection`
  },
})

@sandersn
Copy link
Member

sandersn commented Dec 4, 2023

Looks to me like this fix should only apply when the initialiser type is not a subtype of the contextual type. The bug's example was initialiser=500, context=never, right?

Actually, isAssignableTo("RIGHT", "RIGHT" | "LEFT") is true -- why then does it use the initialiser type instead of the contextual type? Does the widening give string for the initialiser instead? Maybe widening is not right here.

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.

Need to avoid the break found by the user tests. Probably has to do with widening the initialiser type?

@gabritto
Copy link
Member

gabritto commented Dec 4, 2023

I thought this change would be ok because, assuming the widened initializer type is IT and the contextual type is CT, picking a type IT such that CT is assignable to IT would make the function type (x: IT) => ReturnType assignable to (x: CT) => ReturnType , which is the type the context expects for the function.
But as pointed out by the break example, that only accounts for the caller/context perspective: having a parameter that had type CT now have a "supertype" IT is likely to break the implementation of the function.

I think Nathan's solution works, as we'd only trigger the new behavior in cases where currently we issue an error:
we should only pick the widened initializer type if the non-widened initializer type is not assignable to the contextual type.

@Andarist
Copy link
Contributor Author

Andarist commented Dec 4, 2023

Yes, the problem is with widening. I moved the widening call to be within this if block that prefers the initializer's type and it seems to do the trick. I was also considering using checkExpressionWithContextualType - maybe there is a test case to be found here that would require it? One that would, for example, involve a context-sensitive function in the initializer?

let type = tryGetTypeAtPosition(context, i);
if (type && declaration.initializer) {
const initializerType = checkDeclarationInitializer(declaration, CheckMode.Normal);
if (!isTypeAssignableTo(initializerType, type) && isTypeAssignableTo(type, initializerType)) {
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 you want to use the widened initializer type in this second condition (isTypeAssignableTo(type, initializerType)), because consider the following example:

declare function test<
  TContext,
  TMethods extends Record<string, (ctx: TContext, ...args: (1 | 2)[]) => unknown>,
>(context: TContext, methods: TMethods): void;

test(
  {
    count: 0,
  },
  {
    checkLimit: (ctx, max = 3) => {},
  },
);

The initializer type is 3, I think, and the contextual type is 1 | 2. We will still error on that case, and we still want to pick type number over type 1 | 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


create<GraphActions>({
setDirection: (direction = "RIGHT") => {
direction; // CanvasDirection
Copy link
Member

Choose a reason for hiding this comment

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

Can you modify this test so that instead of direction we have something like f(direction) where f takes a CanvasDirection? I think it makes more clear that this would break if we picked parameter type string over CanvasDirection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do u mean smth like this?

type CanvasDirection = "RIGHT" | "LEFT";

interface GraphActions {
  setDirection: (setter: (direction: CanvasDirection) => void) => void;
}

export declare function create<T>(config: T): void;

create<GraphActions>({
  setDirection: (setter = (direction: string) => {}) => {
    setter;
  },
});

Copy link
Member

Choose a reason for hiding this comment

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

I meant something like:

type CanvasDirection = "RIGHT" | "LEFT";

interface GraphActions {
  setDirection: (direction: CanvasDirection) => void;
}

declare function takesDirection(x: CanvasDirection): void;
export declare function create<T>(config: T): void;

create<GraphActions>({
  setDirection: (direction = "RIGHT") => {
    takesDirection(direction);
  },
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, makes sense - thanks for the clarification

@Andarist Andarist requested review from gabritto and sandersn December 4, 2023 22:10
@gabritto
Copy link
Member

gabritto commented Dec 5, 2023

@typescript-bot run DT
@typescript-bot user test this
@typescript-bot test top100
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 5, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 5, 2023

Heya @gabritto, I've started to run the regular perf test suite on this PR at 7a7f6aa. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 5, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 5, 2023

Heya @gabritto, I've started to run the diff-based top-repos suite on this PR at 7a7f6aa. You can monitor the build here.

Update: The results are in!

@gabritto
Copy link
Member

gabritto commented Dec 5, 2023

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 5, 2023

Heya @gabritto, I've started to run the tarball bundle task on this PR at 7a7f6aa. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 5, 2023

Hey @gabritto, 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/158962/artifacts?artifactName=tgz&fileId=4446DDD47E86ED9D1FBD49746BD6A0668BFC21CCBEA8D64591E7F37CC04FD58902&fileName=/typescript-5.4.0-insiders.20231205.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]".;

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,396k (± 0.01%) 295,367k (± 0.00%) -29k (- 0.01%) 295,356k 295,381k p=0.045 n=6
Parse Time 2.65s (± 0.15%) 2.65s (± 0.28%) ~ 2.64s 2.66s p=0.389 n=6
Bind Time 0.82s (± 0.00%) 0.82s (± 0.00%) ~ 0.82s 0.82s p=1.000 n=6
Check Time 8.13s (± 0.42%) 8.12s (± 0.47%) ~ 8.07s 8.16s p=0.466 n=6
Emit Time 7.08s (± 0.39%) 7.08s (± 0.19%) ~ 7.07s 7.10s p=0.744 n=6
Total Time 18.69s (± 0.24%) 18.67s (± 0.23%) ~ 18.62s 18.73s p=0.630 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 194,315k (± 1.61%) 193,808k (± 1.49%) ~ 191,385k 197,455k p=0.471 n=6
Parse Time 1.35s (± 0.60%) 1.37s (± 1.10%) ~ 1.34s 1.38s p=0.085 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.26s (± 0.35%) 9.28s (± 0.35%) ~ 9.24s 9.33s p=0.518 n=6
Emit Time 2.63s (± 0.20%) 2.62s (± 1.29%) ~ 2.59s 2.68s p=0.210 n=6
Total Time 13.96s (± 0.19%) 13.99s (± 0.49%) ~ 13.92s 14.11s p=0.936 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,394k (± 0.01%) 347,374k (± 0.01%) ~ 347,343k 347,395k p=0.199 n=6
Parse Time 2.45s (± 0.48%) 2.46s (± 0.57%) ~ 2.44s 2.48s p=0.188 n=6
Bind Time 0.93s (± 0.56%) 0.92s (± 0.59%) ~ 0.92s 0.93s p=0.640 n=6
Check Time 6.90s (± 0.32%) 6.90s (± 0.47%) ~ 6.87s 6.95s p=0.371 n=6
Emit Time 4.05s (± 0.44%) 4.04s (± 0.30%) ~ 4.03s 4.06s p=0.623 n=6
Total Time 14.33s (± 0.21%) 14.32s (± 0.31%) ~ 14.29s 14.40s p=0.739 n=6
TFS - node (v18.15.0, x64)
Memory used 302,682k (± 0.01%) 302,660k (± 0.00%) ~ 302,641k 302,678k p=0.261 n=6
Parse Time 1.99s (± 1.23%) 2.01s (± 0.73%) ~ 1.99s 2.03s p=0.252 n=6
Bind Time 1.00s (± 0.98%) 1.01s (± 0.97%) ~ 1.00s 1.02s p=0.116 n=6
Check Time 6.29s (± 0.36%) 6.27s (± 0.34%) ~ 6.25s 6.31s p=0.089 n=6
Emit Time 3.58s (± 0.54%) 3.59s (± 0.91%) ~ 3.56s 3.65s p=0.627 n=6
Total Time 12.87s (± 0.33%) 12.88s (± 0.35%) ~ 12.83s 12.95s p=0.414 n=6
material-ui - node (v18.15.0, x64)
Memory used 506,738k (± 0.01%) 506,742k (± 0.00%) ~ 506,702k 506,761k p=0.575 n=6
Parse Time 2.58s (± 0.53%) 2.59s (± 0.63%) ~ 2.57s 2.61s p=0.804 n=6
Bind Time 0.99s (± 0.99%) 0.99s (± 1.64%) ~ 0.97s 1.01s p=0.867 n=6
Check Time 16.88s (± 0.25%) 16.83s (± 0.29%) ~ 16.79s 16.93s p=0.125 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.45s (± 0.22%) 20.41s (± 0.31%) ~ 20.35s 20.53s p=0.172 n=6
xstate - node (v18.15.0, x64)
Memory used 512,788k (± 0.01%) 512,726k (± 0.01%) ~ 512,593k 512,787k p=0.173 n=6
Parse Time 3.27s (± 0.46%) 3.27s (± 0.30%) ~ 3.26s 3.28s p=0.865 n=6
Bind Time 1.53s (± 0.27%) 1.54s (± 0.36%) ~ 1.53s 1.54s p=0.282 n=6
Check Time 2.80s (± 0.83%) 2.80s (± 0.67%) ~ 2.79s 2.84s p=0.672 n=6
Emit Time 0.08s (± 4.99%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=0.405 n=6
Total Time 7.68s (± 0.35%) 7.69s (± 0.27%) ~ 7.66s 7.72s p=0.808 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)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,345ms (± 0.62%) 2,338ms (± 0.60%) ~ 2,321ms 2,360ms p=0.298 n=6
Req 2 - geterr 5,390ms (± 1.17%) 5,447ms (± 1.77%) ~ 5,346ms 5,549ms p=0.336 n=6
Req 3 - references 325ms (± 2.11%) 324ms (± 0.80%) ~ 320ms 326ms p=0.683 n=6
Req 4 - navto 279ms (± 0.72%) 277ms (± 1.34%) ~ 273ms 281ms p=0.317 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 82ms (± 5.89%) 85ms (± 6.80%) ~ 76ms 90ms p=0.277 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,480ms (± 0.90%) 2,460ms (± 1.52%) ~ 2,395ms 2,498ms p=0.470 n=6
Req 2 - geterr 4,146ms (± 1.94%) 4,137ms (± 2.00%) ~ 4,056ms 4,218ms p=0.336 n=6
Req 3 - references 339ms (± 1.49%) 342ms (± 1.61%) ~ 335ms 348ms p=0.288 n=6
Req 4 - navto 284ms (± 0.22%) 284ms (± 0.29%) ~ 283ms 285ms p=0.432 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 82ms (± 7.14%) 85ms (± 7.47%) ~ 77ms 90ms p=0.566 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,596ms (± 0.37%) 2,597ms (± 0.61%) ~ 2,567ms 2,611ms p=0.689 n=6
Req 2 - geterr 1,680ms (± 2.10%) 1,651ms (± 1.14%) ~ 1,627ms 1,680ms p=0.093 n=6
Req 3 - references 112ms (±10.14%) 106ms (± 7.44%) ~ 102ms 122ms p=0.868 n=6
Req 4 - navto 365ms (± 0.22%) 364ms (± 0.77%) ~ 359ms 367ms p=0.677 n=6
Req 5 - completionInfo count 2,073 (± 0.00%) 2,073 (± 0.00%) ~ 2,073 2,073 p=1.000 n=6
Req 5 - completionInfo 314ms (± 0.99%) 310ms (± 1.40%) ~ 301ms 312ms p=0.114 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 152.78ms (± 0.20%) 152.72ms (± 0.20%) -0.06ms (- 0.04%) 151.60ms 156.67ms p=0.029 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 228.11ms (± 0.17%) 227.92ms (± 0.16%) -0.19ms (- 0.08%) 226.53ms 232.61ms p=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 229.50ms (± 0.20%) 229.44ms (± 0.20%) ~ 227.74ms 235.85ms p=0.089 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 229.17ms (± 0.17%) 229.12ms (± 0.17%) ~ 227.68ms 233.24ms p=0.313 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

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

There were infrastructure failures potentially unrelated to your change:

  • 2 instances of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

puppeteer

packages/browsers/test/src/tsconfig.json

@gabritto
Copy link
Member

gabritto commented Dec 5, 2023

I was also considering using checkExpressionWithContextualType - maybe there is a test case to be found here that would require it? One that would, for example, involve a context-sensitive function in the initializer?

I think that's worth thinking about, but to be honest I couldn't so far think about an example, so I don't know if it matters.

@typescript-bot
Copy link
Collaborator

Hey @gabritto, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Contextual never parameter type gets precedence over the initializer's type
6 participants