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:
Oleksandr T
2022-08-26 10:05:52 -07:00
committed by GitHub
co-authored by Ryan Cavanaugh
parent 07157914eb
commit 164dddc48e
102 changed files with 3172 additions and 449 deletions
+4
View File
@@ -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)) {
+1
View File
@@ -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:
+4
View File
@@ -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);
}
+1
View File
@@ -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]])