Avoid silentNeverType leaking into generator types inferred based on inner generic calls at yields#62283
Conversation
…n inner generic calls at `yield`s
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
1 similar comment
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where silentNeverType was incorrectly leaking into generator types when inferring types based on inner generic calls at yield expressions. The change improves type inference for generators that use yield* with generic function calls by preventing premature type narrowing to never.
Key changes:
- Removes special handling of
silentNeverTypein yield expression type checking - Modifies check mode for yield expressions to skip generic function checks
- Updates test baselines to reflect improved type inference from
nevertoany
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/compiler/checker.ts | Core fix removing silentNeverType handling and adjusting check modes |
| tests/cases/compiler/genericCallAtYieldExpressionInGenericCall1.ts | Additional test cases for the fix |
| tests/baselines/reference/*.types | Updated type baselines showing improved inference |
| tests/baselines/reference/*.errors.txt | New error baselines for test cases |
| tests/baselines/reference/*.symbols | Symbol baselines for new test cases |
src/compiler/checker.ts
Outdated
| const isAsync = (getFunctionFlags(func) & FunctionFlags.Async) !== 0; | ||
| forEachYieldExpression(func.body as Block, yieldExpression => { | ||
| const yieldExpressionType = yieldExpression.expression ? checkExpression(yieldExpression.expression, checkMode) : undefinedWideningType; | ||
| const yieldExpressionType = yieldExpression.expression ? checkExpression(yieldExpression.expression, checkMode && checkMode & ~CheckMode.SkipGenericFunctions) : undefinedWideningType; |
There was a problem hiding this comment.
this is exactly what the cousin (checkAndAggregateReturnExpressionTypes) of this function (checkAndAggregateYieldOperandTypes) does
| > : ^ ^^ ^^ ^^^^^ | ||
| >function* <T>(value: T) { const result = yield* inner(value); // ok} : <T>(value: T) => Generator<never, void, never> | ||
| > : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| >function* <T>(value: T) { const result = yield* inner(value); // ok} : <T>(value: T) => Generator<any, void, any> |
There was a problem hiding this comment.
the new results here are better and match the other results that have inner~ function called beforehand (when its precomputed result is yield*ed)
|
@typescript-bot test it |
|
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
|
@jakebailey Here are the results of running the user tests with tsc comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
|
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jakebailey Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
This is an improvement over one of the recent PRs: #61317