-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Fixed an issue with satisfies
"resolving" generic types of references
#60710
base: main
Are you sure you want to change the base?
Fixed an issue with satisfies
"resolving" generic types of references
#60710
Conversation
const exprType = checkExpression(expression, checkMode); | ||
const targetType = getTypeFromTypeNode(target); | ||
if (isErrorType(targetType)) { | ||
return targetType; | ||
} | ||
const errorNode = findAncestor(target.parent, n => n.kind === SyntaxKind.SatisfiesExpression || n.kind === SyntaxKind.JSDocSatisfiesTag); | ||
checkTypeAssignableToAndOptionallyElaborate(exprType, targetType, errorNode, expression, Diagnostics.Type_0_does_not_satisfy_the_expected_type_1); | ||
return exprType; | ||
return checkExpression(expression, checkMode | CheckMode.SatisfiesOutput); |
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.
exprType
is used to check the assignability, it may contain "resolved" types for narrowable references. So the assignability works like it works in:
const x: "A" = genericReferenceNarrowedDownToA;
But the output type is different because we should propagate that "resolved" type in:
// actual on main: `"A"`
// expected: `AB extends "A" | "B"`
const x = genericReferenceNarrowedDownToA satisfies "A";
@@ -160,8 +160,8 @@ function g1<T extends Box<T> | undefined>(x: T) { | |||
> : ^^^^^^^ | |||
>isBox : (x: any) => x is Box<unknown> | |||
> : ^ ^^ ^^^^^ | |||
>x : Box<T> | undefined | |||
> : ^^^^^^^^^^^^^^^^^^ | |||
>x : T |
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.
all the baseline changes like this are caused by the fact that now hasContextualTypeWithNoGenericTypes
returns false
when the contextual type is any, and thus substituteConstraints
gets computed as false
in getNarrowableTypeForReference
description: "Add missing function declaration 'added2'", | ||
index: 1, |
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 was a mistake in the original test case, goTo.marker("2")
has no effect on verify.codeFix
, we need to use a global index here to test the codefix at that marker
@@ -19,24 +19,24 @@ verify.codeFix({ | |||
added2(et) | |||
} | |||
|
|||
function added1(et: string) { | |||
function added1<T extends "phone" | "home">(et: T) { |
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.
I believe this was the original true intention here but the type widened since it had a union constraint. This was introduced in #49727 , cc @JoshuaKGoldberg
@@ -15,7 +15,7 @@ verify.codeFix({ | |||
added(keyofTypeof); | |||
} | |||
|
|||
function added(keyofTypeof: string | number | symbol) { | |||
function added<T>(keyofTypeof: keyof T) { |
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 isn't a particularly great codefix... since keyof T
when T
doesn't appear "naked" somewhere in the parameters list is usually a lousy parameter. I don't think it's worth fighting it here though as it could appear naked somewhere.
: getContextualType(node, /*contextFlags*/ undefined)); | ||
return contextualType && !isGenericType(contextualType); | ||
getContextualType(node, (checkMode & CheckMode.RestBindingElement ? ContextFlags.SkipBindingPatterns : 0) | (checkMode & CheckMode.SatisfiesOutput ? ContextFlags.SkipSatisfies : 0)); | ||
return contextualType && !(contextualType.flags & TypeFlags.Any) && !isGenericType(contextualType); |
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 added !(contextualType.flags & TypeFlags.Any)
bit here isn't exactly related to satisfies
at all. I have added it to account for auto types, that affected all the baselines that had any
as the contextual type in a few places. It also affected those codefixes for missing function declarations since the error type (a special kind of any) was the contextual type for those arguments here. I think those changes are positive
@typescript-bot test it |
@jakebailey Here are the results of running the user tests with tsc comparing Everything looks good! |
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
@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! |
fixes #52394
fixes #60698