diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3be17bfdaa6da..41164ff435e21 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -34167,7 +34167,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function hasEmptyObjectIntersection(type: Type): boolean { - return someType(type, t => t === unknownEmptyObjectType || !!(t.flags & TypeFlags.Intersection) && some((t as IntersectionType).types, isEmptyAnonymousObjectType)); + return someType(type, t => t === unknownEmptyObjectType || !!(t.flags & TypeFlags.Intersection) && isEmptyAnonymousObjectType(getBaseConstraintOrType(t))); } function checkInExpression(left: Expression, right: Expression, leftType: Type, rightType: Type): Type { diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=false).errors.txt b/tests/baselines/reference/inKeywordTypeguard(strict=false).errors.txt index 009acf38c2b18..7d8bd0bea9a4b 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=false).errors.txt +++ b/tests/baselines/reference/inKeywordTypeguard(strict=false).errors.txt @@ -420,4 +420,16 @@ tests/cases/compiler/inKeywordTypeguard.ts(186,21): error TS2322: Type 'T' is no const checkIsTouchDevice = () => "ontouchstart" in window || "msMaxTouchPoints" in window.navigator; + + // Repro from #51501 + + function isHTMLTable(table: T): boolean { + return !!table && 'html' in table; + } + + // Repro from #51549 + + const f =

(a: P & {}) => { + "foo" in a; + }; \ No newline at end of file diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=false).js b/tests/baselines/reference/inKeywordTypeguard(strict=false).js index d254218557fa3..ae1ccbb43c5be 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=false).js +++ b/tests/baselines/reference/inKeywordTypeguard(strict=false).js @@ -341,6 +341,18 @@ function foo(value: A) { const checkIsTouchDevice = () => "ontouchstart" in window || "msMaxTouchPoints" in window.navigator; + +// Repro from #51501 + +function isHTMLTable(table: T): boolean { + return !!table && 'html' in table; +} + +// Repro from #51549 + +const f =

(a: P & {}) => { + "foo" in a; +}; //// [inKeywordTypeguard.js] @@ -655,3 +667,11 @@ function foo(value) { } // Repro from #50954 const checkIsTouchDevice = () => "ontouchstart" in window || "msMaxTouchPoints" in window.navigator; +// Repro from #51501 +function isHTMLTable(table) { + return !!table && 'html' in table; +} +// Repro from #51549 +const f = (a) => { + "foo" in a; +}; diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=false).symbols b/tests/baselines/reference/inKeywordTypeguard(strict=false).symbols index c7ad966debf4d..9444bf3fc988c 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=false).symbols +++ b/tests/baselines/reference/inKeywordTypeguard(strict=false).symbols @@ -853,3 +853,29 @@ const checkIsTouchDevice = () => >window : Symbol(window, Decl(lib.dom.d.ts, --, --)) >navigator : Symbol(navigator, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +// Repro from #51501 + +function isHTMLTable(table: T): boolean { +>isHTMLTable : Symbol(isHTMLTable, Decl(inKeywordTypeguard.ts, 341, 71)) +>T : Symbol(T, Decl(inKeywordTypeguard.ts, 345, 21)) +>table : Symbol(table, Decl(inKeywordTypeguard.ts, 345, 46)) +>T : Symbol(T, Decl(inKeywordTypeguard.ts, 345, 21)) + + return !!table && 'html' in table; +>table : Symbol(table, Decl(inKeywordTypeguard.ts, 345, 46)) +>table : Symbol(table, Decl(inKeywordTypeguard.ts, 345, 46)) +} + +// Repro from #51549 + +const f =

(a: P & {}) => { +>f : Symbol(f, Decl(inKeywordTypeguard.ts, 351, 5)) +>P : Symbol(P, Decl(inKeywordTypeguard.ts, 351, 11)) +>a : Symbol(a, Decl(inKeywordTypeguard.ts, 351, 29)) +>P : Symbol(P, Decl(inKeywordTypeguard.ts, 351, 11)) + + "foo" in a; +>a : Symbol(a, Decl(inKeywordTypeguard.ts, 351, 29)) + +}; + diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=false).types b/tests/baselines/reference/inKeywordTypeguard(strict=false).types index 710206712629b..152eba6bda250 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=false).types +++ b/tests/baselines/reference/inKeywordTypeguard(strict=false).types @@ -1056,3 +1056,34 @@ const checkIsTouchDevice = () => >window : Window & typeof globalThis >navigator : Navigator +// Repro from #51501 + +function isHTMLTable(table: T): boolean { +>isHTMLTable : (table: T) => boolean +>null : null +>table : T + + return !!table && 'html' in table; +>!!table && 'html' in table : boolean +>!!table : boolean +>!table : boolean +>table : T +>'html' in table : boolean +>'html' : "html" +>table : T +} + +// Repro from #51549 + +const f =

(a: P & {}) => { +>f :

(a: P & {}) => void +>

(a: P & {}) => { "foo" in a;} :

(a: P & {}) => void +>a : P & {} + + "foo" in a; +>"foo" in a : boolean +>"foo" : "foo" +>a : P & {} + +}; + diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=true).errors.txt b/tests/baselines/reference/inKeywordTypeguard(strict=true).errors.txt index 1f11114fbd02c..d47a0718aac8a 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=true).errors.txt +++ b/tests/baselines/reference/inKeywordTypeguard(strict=true).errors.txt @@ -440,4 +440,16 @@ tests/cases/compiler/inKeywordTypeguard.ts(186,21): error TS2638: Type 'NonNulla const checkIsTouchDevice = () => "ontouchstart" in window || "msMaxTouchPoints" in window.navigator; + + // Repro from #51501 + + function isHTMLTable(table: T): boolean { + return !!table && 'html' in table; + } + + // Repro from #51549 + + const f =

(a: P & {}) => { + "foo" in a; + }; \ No newline at end of file diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=true).js b/tests/baselines/reference/inKeywordTypeguard(strict=true).js index 9acc8ca7520e4..73b2cf77cae44 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=true).js +++ b/tests/baselines/reference/inKeywordTypeguard(strict=true).js @@ -341,6 +341,18 @@ function foo(value: A) { const checkIsTouchDevice = () => "ontouchstart" in window || "msMaxTouchPoints" in window.navigator; + +// Repro from #51501 + +function isHTMLTable(table: T): boolean { + return !!table && 'html' in table; +} + +// Repro from #51549 + +const f =

(a: P & {}) => { + "foo" in a; +}; //// [inKeywordTypeguard.js] @@ -656,3 +668,11 @@ function foo(value) { } // Repro from #50954 const checkIsTouchDevice = () => "ontouchstart" in window || "msMaxTouchPoints" in window.navigator; +// Repro from #51501 +function isHTMLTable(table) { + return !!table && 'html' in table; +} +// Repro from #51549 +const f = (a) => { + "foo" in a; +}; diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=true).symbols b/tests/baselines/reference/inKeywordTypeguard(strict=true).symbols index c7ad966debf4d..9444bf3fc988c 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=true).symbols +++ b/tests/baselines/reference/inKeywordTypeguard(strict=true).symbols @@ -853,3 +853,29 @@ const checkIsTouchDevice = () => >window : Symbol(window, Decl(lib.dom.d.ts, --, --)) >navigator : Symbol(navigator, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +// Repro from #51501 + +function isHTMLTable(table: T): boolean { +>isHTMLTable : Symbol(isHTMLTable, Decl(inKeywordTypeguard.ts, 341, 71)) +>T : Symbol(T, Decl(inKeywordTypeguard.ts, 345, 21)) +>table : Symbol(table, Decl(inKeywordTypeguard.ts, 345, 46)) +>T : Symbol(T, Decl(inKeywordTypeguard.ts, 345, 21)) + + return !!table && 'html' in table; +>table : Symbol(table, Decl(inKeywordTypeguard.ts, 345, 46)) +>table : Symbol(table, Decl(inKeywordTypeguard.ts, 345, 46)) +} + +// Repro from #51549 + +const f =

(a: P & {}) => { +>f : Symbol(f, Decl(inKeywordTypeguard.ts, 351, 5)) +>P : Symbol(P, Decl(inKeywordTypeguard.ts, 351, 11)) +>a : Symbol(a, Decl(inKeywordTypeguard.ts, 351, 29)) +>P : Symbol(P, Decl(inKeywordTypeguard.ts, 351, 11)) + + "foo" in a; +>a : Symbol(a, Decl(inKeywordTypeguard.ts, 351, 29)) + +}; + diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=true).types b/tests/baselines/reference/inKeywordTypeguard(strict=true).types index 86da8b3e869cb..491c4858e543e 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=true).types +++ b/tests/baselines/reference/inKeywordTypeguard(strict=true).types @@ -1056,3 +1056,34 @@ const checkIsTouchDevice = () => >window : Window & typeof globalThis >navigator : Navigator +// Repro from #51501 + +function isHTMLTable(table: T): boolean { +>isHTMLTable : (table: T) => boolean +>null : null +>table : T + + return !!table && 'html' in table; +>!!table && 'html' in table : boolean +>!!table : boolean +>!table : boolean +>table : T +>'html' in table : boolean +>'html' : "html" +>table : NonNullable +} + +// Repro from #51549 + +const f =

(a: P & {}) => { +>f :

(a: P & {}) => void +>

(a: P & {}) => { "foo" in a;} :

(a: P & {}) => void +>a : P & {} + + "foo" in a; +>"foo" in a : boolean +>"foo" : "foo" +>a : P & {} + +}; + diff --git a/tests/cases/compiler/inKeywordTypeguard.ts b/tests/cases/compiler/inKeywordTypeguard.ts index 47266e55bd901..0c74dcded90ba 100644 --- a/tests/cases/compiler/inKeywordTypeguard.ts +++ b/tests/cases/compiler/inKeywordTypeguard.ts @@ -343,3 +343,15 @@ function foo(value: A) { const checkIsTouchDevice = () => "ontouchstart" in window || "msMaxTouchPoints" in window.navigator; + +// Repro from #51501 + +function isHTMLTable(table: T): boolean { + return !!table && 'html' in table; +} + +// Repro from #51549 + +const f =

(a: P & {}) => { + "foo" in a; +};