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
+13
View File
@@ -181,6 +181,7 @@ namespace ts {
RequireKeyword,
NumberKeyword,
ObjectKeyword,
SatisfiesKeyword,
SetKeyword,
StringKeyword,
SymbolKeyword,
@@ -274,6 +275,7 @@ namespace ts {
NonNullExpression,
MetaProperty,
SyntheticExpression,
SatisfiesExpression,
// Misc
TemplateSpan,
@@ -607,6 +609,7 @@ namespace ts {
| SyntaxKind.OverrideKeyword
| SyntaxKind.RequireKeyword
| SyntaxKind.ReturnKeyword
| SyntaxKind.SatisfiesKeyword
| SyntaxKind.SetKeyword
| SyntaxKind.StaticKeyword
| SyntaxKind.StringKeyword
@@ -1007,6 +1010,7 @@ namespace ts {
| ExpressionWithTypeArguments
| AsExpression
| NonNullExpression
| SatisfiesExpression
| MetaProperty
| TemplateSpan
| Block
@@ -2815,6 +2819,12 @@ namespace ts {
readonly expression: UnaryExpression;
}
export interface SatisfiesExpression extends Expression {
readonly kind: SyntaxKind.SatisfiesExpression;
readonly expression: Expression;
readonly type: TypeNode;
}
export type AssertionExpression =
| TypeAssertion
| AsExpression
@@ -7520,6 +7530,7 @@ namespace ts {
export type OuterExpression =
| ParenthesizedExpression
| TypeAssertion
| SatisfiesExpression
| AsExpression
| NonNullExpression
| PartiallyEmittedExpression;
@@ -7856,6 +7867,8 @@ namespace ts {
updateNonNullChain(node: NonNullChain, expression: Expression): NonNullChain;
createMetaProperty(keywordToken: MetaProperty["keywordToken"], name: Identifier): MetaProperty;
updateMetaProperty(node: MetaProperty, name: Identifier): MetaProperty;
createSatisfiesExpression(expression: Expression, type: TypeNode): SatisfiesExpression;
updateSatisfiesExpression(node: SatisfiesExpression, expression: Expression, type: TypeNode): SatisfiesExpression;
//
// Misc