-
Notifications
You must be signed in to change notification settings - Fork 13k
Avoid silentNeverType
leaking into generator types inferred based on inner generic calls at yield
s
#62283
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
base: main
Are you sure you want to change the base?
Avoid silentNeverType
leaking into generator types inferred based on inner generic calls at yield
s
#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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
silentNeverType
in yield expression type checking - Modifies check mode for yield expressions to skip generic function checks
- Updates test baselines to reflect improved type inference from
never
toany
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 |
@@ -39208,7 +39207,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
const nextTypes: Type[] = []; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is exactly what the cousin (checkAndAggregateReturnExpressionTypes
) of this function (checkAndAggregateYieldOperandTypes
) does
@@ -47,8 +47,8 @@ outer(function* <T>(value: T) { | |||
> : ^^^^ | |||
>outer : <A>(body: (value: A) => Generator<any, any, any>) => void | |||
> : ^ ^^ ^^ ^^^^^ | |||
>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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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