mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
feat(7481): Operator to ensure an expression is contextually typed by, and satisfies, some type (#46827)
* feat(7481): add explicit type compatibility check with 'satisfies' expression * Add failing test for lack of intersectioned contextual type * Implement the behavior * Add test corresponding to the 'if' * Add test based on defined scenarios * remove isExpression in favor of using type casting * move tests from compiler to conformance folder * update baseline * add missing contextFlags argument * use asserted type * accept baseline Co-authored-by: Ryan Cavanaugh <ryanca@microsoft.com>
This commit is contained in:
co-authored by
Ryan Cavanaugh
parent
07157914eb
commit
164dddc48e
@@ -449,6 +449,10 @@ namespace ts.CallHierarchy {
|
||||
recordCallSite(node as AccessExpression);
|
||||
forEachChild(node, collect);
|
||||
break;
|
||||
case SyntaxKind.SatisfiesExpression:
|
||||
// do not descend into the type side of an assertion
|
||||
collect((node as SatisfiesExpression).expression);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPartOfTypeNode(node)) {
|
||||
|
||||
@@ -369,6 +369,7 @@ namespace ts {
|
||||
case SyntaxKind.InstanceOfKeyword:
|
||||
case SyntaxKind.InKeyword:
|
||||
case SyntaxKind.AsKeyword:
|
||||
case SyntaxKind.SatisfiesKeyword:
|
||||
case SyntaxKind.EqualsEqualsToken:
|
||||
case SyntaxKind.ExclamationEqualsToken:
|
||||
case SyntaxKind.EqualsEqualsEqualsToken:
|
||||
|
||||
@@ -2675,6 +2675,9 @@ namespace ts.Completions {
|
||||
|
||||
case SyntaxKind.ExtendsKeyword:
|
||||
return parentKind === SyntaxKind.TypeParameter;
|
||||
|
||||
case SyntaxKind.SatisfiesKeyword:
|
||||
return parentKind === SyntaxKind.SatisfiesExpression;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -3962,6 +3965,7 @@ namespace ts.Completions {
|
||||
return kind === SyntaxKind.AsyncKeyword
|
||||
|| kind === SyntaxKind.AwaitKeyword
|
||||
|| kind === SyntaxKind.AsKeyword
|
||||
|| kind === SyntaxKind.SatisfiesKeyword
|
||||
|| kind === SyntaxKind.TypeKeyword
|
||||
|| !isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind);
|
||||
}
|
||||
|
||||
@@ -449,6 +449,7 @@ namespace ts.formatting {
|
||||
case SyntaxKind.TypePredicate:
|
||||
case SyntaxKind.UnionType:
|
||||
case SyntaxKind.IntersectionType:
|
||||
case SyntaxKind.SatisfiesExpression:
|
||||
return true;
|
||||
|
||||
// equals in binding elements: function foo([[x, y] = [1, 2]])
|
||||
|
||||
Reference in New Issue
Block a user