diff --git a/internal/checker/flow.go b/internal/checker/flow.go index 4ef3469f75..0fec14d3f0 100644 --- a/internal/checker/flow.go +++ b/internal/checker/flow.go @@ -388,7 +388,7 @@ func (c *Checker) narrowType(f *FlowState, t *Type, expr *ast.Node, assumeTrue b return c.narrowTypeByTruthiness(f, t, expr, assumeTrue) case ast.KindCallExpression: return c.narrowTypeByCallExpression(f, t, expr, assumeTrue) - case ast.KindParenthesizedExpression, ast.KindNonNullExpression: + case ast.KindParenthesizedExpression, ast.KindNonNullExpression, ast.KindSatisfiesExpression: return c.narrowType(f, t, expr.Expression(), assumeTrue) case ast.KindBinaryExpression: return c.narrowTypeByBinaryExpression(f, t, expr.AsBinaryExpression(), assumeTrue) @@ -1572,7 +1572,7 @@ func (c *Checker) isMatchingReference(source *ast.Node, target *ast.Node) bool { return target.Kind == ast.KindThisKeyword case ast.KindSuperKeyword: return target.Kind == ast.KindSuperKeyword - case ast.KindNonNullExpression, ast.KindParenthesizedExpression: + case ast.KindNonNullExpression, ast.KindParenthesizedExpression, ast.KindSatisfiesExpression: return c.isMatchingReference(source.Expression(), target) case ast.KindPropertyAccessExpression, ast.KindElementAccessExpression: if sourcePropertyName, ok := c.getAccessedPropertyName(source); ok { diff --git a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.errors.txt b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.errors.txt index 5d8baf6a73..e5f1f60cfc 100644 --- a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.errors.txt @@ -20,12 +20,9 @@ inferTypePredicates.ts(115,7): error TS2322: Type 'string | number' is not assig inferTypePredicates.ts(133,7): error TS2322: Type 'object' is not assignable to type 'Date'. Type '{}' is missing the following properties from type 'Date': toDateString, toTimeString, toLocaleDateString, toLocaleTimeString, and 37 more. inferTypePredicates.ts(205,7): error TS2741: Property 'z' is missing in type 'C1' but required in type 'C2'. -inferTypePredicates.ts(281,7): error TS2322: Type '(number | null)[]' is not assignable to type 'number[]'. - Type 'number | null' is not assignable to type 'number'. - Type 'null' is not assignable to type 'number'. -==== inferTypePredicates.ts (12 errors) ==== +==== inferTypePredicates.ts (11 errors) ==== // https://github.com/microsoft/TypeScript/issues/16069 const numsOrNull = [1, 2, 3, 4, null]; @@ -341,10 +338,6 @@ inferTypePredicates.ts(281,7): error TS2322: Type '(number | null)[]' is not ass // https://github.com/microsoft/TypeScript/issues/60778 const arrTest: Array = [1, 2, null, 3].filter( - ~~~~~~~ -!!! error TS2322: Type '(number | null)[]' is not assignable to type 'number[]'. -!!! error TS2322: Type 'number | null' is not assignable to type 'number'. -!!! error TS2322: Type 'null' is not assignable to type 'number'. (x) => (x != null) satisfies boolean, ); diff --git a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.errors.txt.diff index c6562ffc97..0a87fa8093 100644 --- a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.errors.txt.diff @@ -8,19 +8,9 @@ +inferTypePredicates.ts(133,7): error TS2322: Type 'object' is not assignable to type 'Date'. + Type '{}' is missing the following properties from type 'Date': toDateString, toTimeString, toLocaleDateString, toLocaleTimeString, and 37 more. inferTypePredicates.ts(205,7): error TS2741: Property 'z' is missing in type 'C1' but required in type 'C2'. -- -- --==== inferTypePredicates.ts (11 errors) ==== -+inferTypePredicates.ts(281,7): error TS2322: Type '(number | null)[]' is not assignable to type 'number[]'. -+ Type 'number | null' is not assignable to type 'number'. -+ Type 'null' is not assignable to type 'number'. -+ -+ -+==== inferTypePredicates.ts (12 errors) ==== - // https://github.com/microsoft/TypeScript/issues/16069 - - const numsOrNull = [1, 2, 3, 4, null]; -@@= skipped -167, +171 lines =@@ + + +@@= skipped -167, +168 lines =@@ if (flakyIsDate(maybeDate)) { let t: Date = maybeDate; // should error ~ @@ -29,15 +19,4 @@ +!!! error TS2322: Type '{}' is missing the following properties from type 'Date': toDateString, toTimeString, toLocaleDateString, toLocaleTimeString, and 37 more. } else { let t: object = maybeDate; // should ok - } -@@= skipped -152, +153 lines =@@ - - // https://github.com/microsoft/TypeScript/issues/60778 - const arrTest: Array = [1, 2, null, 3].filter( -+ ~~~~~~~ -+!!! error TS2322: Type '(number | null)[]' is not assignable to type 'number[]'. -+!!! error TS2322: Type 'number | null' is not assignable to type 'number'. -+!!! error TS2322: Type 'null' is not assignable to type 'number'. - (x) => (x != null) satisfies boolean, - ); - \ No newline at end of file + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.js b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.js index 3f02425b97..aceb8b5452 100644 --- a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.js +++ b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.js @@ -631,4 +631,4 @@ declare const foobarPred: (fb: { }; // https://github.com/microsoft/TypeScript/issues/60778 declare const arrTest: Array; -declare function isEmptyString(x: unknown): boolean; +declare function isEmptyString(x: unknown): x is ""; diff --git a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.js.diff b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.js.diff index 03335c3212..65f04640e8 100644 --- a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.js.diff +++ b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.js.diff @@ -426,5 +426,4 @@ }; +// https://github.com/microsoft/TypeScript/issues/60778 declare const arrTest: Array; --declare function isEmptyString(x: unknown): x is ""; -+declare function isEmptyString(x: unknown): boolean; \ No newline at end of file + declare function isEmptyString(x: unknown): x is ""; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.types b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.types index 3bf7c1e4ce..703f33c1ec 100644 --- a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.types +++ b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.types @@ -1016,7 +1016,7 @@ if (foobarPred(foobar)) { // https://github.com/microsoft/TypeScript/issues/60778 const arrTest: Array = [1, 2, null, 3].filter( >arrTest : number[] ->[1, 2, null, 3].filter( (x) => (x != null) satisfies boolean,) : (number | null)[] +>[1, 2, null, 3].filter( (x) => (x != null) satisfies boolean,) : number[] >[1, 2, null, 3].filter : { (predicate: (value: number | null, index: number, array: (number | null)[]) => value is S, thisArg?: any): S[]; (predicate: (value: number | null, index: number, array: (number | null)[]) => unknown, thisArg?: any): (number | null)[]; } >[1, 2, null, 3] : (number | null)[] >1 : 1 @@ -1025,7 +1025,7 @@ const arrTest: Array = [1, 2, null, 3].filter( >filter : { (predicate: (value: number | null, index: number, array: (number | null)[]) => value is S, thisArg?: any): S[]; (predicate: (value: number | null, index: number, array: (number | null)[]) => unknown, thisArg?: any): (number | null)[]; } (x) => (x != null) satisfies boolean, ->(x) => (x != null) satisfies boolean : (x: number | null) => boolean +>(x) => (x != null) satisfies boolean : (x: number | null) => x is number >x : number | null >(x != null) satisfies boolean : boolean >(x != null) : boolean @@ -1035,7 +1035,7 @@ const arrTest: Array = [1, 2, null, 3].filter( ); function isEmptyString(x: unknown) { ->isEmptyString : (x: unknown) => boolean +>isEmptyString : (x: unknown) => x is "" >x : unknown const rv = x === ""; diff --git a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.types.diff b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.types.diff index a11e849802..27e41e4855 100644 --- a/testdata/baselines/reference/submodule/compiler/inferTypePredicates.types.diff +++ b/testdata/baselines/reference/submodule/compiler/inferTypePredicates.types.diff @@ -141,31 +141,4 @@ +>foobarPred : (fb: { type: "foo"; foo: number; } | { type: "bar"; bar: string; }) => fb is { type: "foo"; foo: number; } >foobar : { type: "foo"; foo: number; } | { type: "bar"; bar: string; } - foobar.foo; -@@= skipped -12, +12 lines =@@ - // https://github.com/microsoft/TypeScript/issues/60778 - const arrTest: Array = [1, 2, null, 3].filter( - >arrTest : number[] -->[1, 2, null, 3].filter( (x) => (x != null) satisfies boolean,) : number[] -+>[1, 2, null, 3].filter( (x) => (x != null) satisfies boolean,) : (number | null)[] - >[1, 2, null, 3].filter : { (predicate: (value: number | null, index: number, array: (number | null)[]) => value is S, thisArg?: any): S[]; (predicate: (value: number | null, index: number, array: (number | null)[]) => unknown, thisArg?: any): (number | null)[]; } - >[1, 2, null, 3] : (number | null)[] - >1 : 1 -@@= skipped -9, +9 lines =@@ - >filter : { (predicate: (value: number | null, index: number, array: (number | null)[]) => value is S, thisArg?: any): S[]; (predicate: (value: number | null, index: number, array: (number | null)[]) => unknown, thisArg?: any): (number | null)[]; } - - (x) => (x != null) satisfies boolean, -->(x) => (x != null) satisfies boolean : (x: number | null) => x is number -+>(x) => (x != null) satisfies boolean : (x: number | null) => boolean - >x : number | null - >(x != null) satisfies boolean : boolean - >(x != null) : boolean -@@= skipped -10, +10 lines =@@ - ); - - function isEmptyString(x: unknown) { -->isEmptyString : (x: unknown) => x is "" -+>isEmptyString : (x: unknown) => boolean - >x : unknown - - const rv = x === ""; \ No newline at end of file + foobar.foo; \ No newline at end of file