diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2134e7f9b2992..595a64777c605 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20459,7 +20459,7 @@ namespace ts { const signature = getEffectsSignature((flow).node); if (signature) { const predicate = getTypePredicateOfSignature(signature); - if (predicate && predicate.kind === TypePredicateKind.AssertsIdentifier) { + if (predicate && predicate.kind === TypePredicateKind.AssertsIdentifier && !predicate.type) { const predicateArgument = (flow).node.arguments[predicate.parameterIndex]; if (predicateArgument && isFalseExpression(predicateArgument)) { return false; diff --git a/tests/baselines/reference/assertionTypePredicates1.errors.txt b/tests/baselines/reference/assertionTypePredicates1.errors.txt index 4555f7b68f390..9fb15f480bf42 100644 --- a/tests/baselines/reference/assertionTypePredicates1.errors.txt +++ b/tests/baselines/reference/assertionTypePredicates1.errors.txt @@ -239,4 +239,12 @@ tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(170,5): error TS thing.good; } } + + // Repro from #38699 + + declare function strictEqual(actual: any, expected: T, message?: string | Error): asserts actual is T; + + const b = false; + strictEqual(false, b); + let b2 = b; \ No newline at end of file diff --git a/tests/baselines/reference/assertionTypePredicates1.js b/tests/baselines/reference/assertionTypePredicates1.js index a9128475c528d..230389b383bbb 100644 --- a/tests/baselines/reference/assertionTypePredicates1.js +++ b/tests/baselines/reference/assertionTypePredicates1.js @@ -190,6 +190,14 @@ function example1(things: Thing[]) { thing.good; } } + +// Repro from #38699 + +declare function strictEqual(actual: any, expected: T, message?: string | Error): asserts actual is T; + +const b = false; +strictEqual(false, b); +let b2 = b; //// [assertionTypePredicates1.js] @@ -374,6 +382,9 @@ function example1(things) { thing.good; } } +var b = false; +strictEqual(false, b); +var b2 = b; //// [assertionTypePredicates1.d.ts] @@ -426,3 +437,6 @@ interface GoodThing { good: true; } declare function example1(things: Thing[]): void; +declare function strictEqual(actual: any, expected: T, message?: string | Error): asserts actual is T; +declare const b = false; +declare let b2: boolean; diff --git a/tests/baselines/reference/assertionTypePredicates1.symbols b/tests/baselines/reference/assertionTypePredicates1.symbols index de13f6395bbf1..7bb70ffcb29a9 100644 --- a/tests/baselines/reference/assertionTypePredicates1.symbols +++ b/tests/baselines/reference/assertionTypePredicates1.symbols @@ -542,3 +542,27 @@ function example1(things: Thing[]) { } } +// Repro from #38699 + +declare function strictEqual(actual: any, expected: T, message?: string | Error): asserts actual is T; +>strictEqual : Symbol(strictEqual, Decl(assertionTypePredicates1.ts, 190, 1)) +>T : Symbol(T, Decl(assertionTypePredicates1.ts, 194, 29)) +>actual : Symbol(actual, Decl(assertionTypePredicates1.ts, 194, 32)) +>expected : Symbol(expected, Decl(assertionTypePredicates1.ts, 194, 44)) +>T : Symbol(T, Decl(assertionTypePredicates1.ts, 194, 29)) +>message : Symbol(message, Decl(assertionTypePredicates1.ts, 194, 57)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>actual : Symbol(actual, Decl(assertionTypePredicates1.ts, 194, 32)) +>T : Symbol(T, Decl(assertionTypePredicates1.ts, 194, 29)) + +const b = false; +>b : Symbol(b, Decl(assertionTypePredicates1.ts, 196, 5)) + +strictEqual(false, b); +>strictEqual : Symbol(strictEqual, Decl(assertionTypePredicates1.ts, 190, 1)) +>b : Symbol(b, Decl(assertionTypePredicates1.ts, 196, 5)) + +let b2 = b; +>b2 : Symbol(b2, Decl(assertionTypePredicates1.ts, 198, 3)) +>b : Symbol(b, Decl(assertionTypePredicates1.ts, 196, 5)) + diff --git a/tests/baselines/reference/assertionTypePredicates1.types b/tests/baselines/reference/assertionTypePredicates1.types index 911f90a4a9dff..c71f0007fa5cf 100644 --- a/tests/baselines/reference/assertionTypePredicates1.types +++ b/tests/baselines/reference/assertionTypePredicates1.types @@ -666,3 +666,25 @@ function example1(things: Thing[]) { } } +// Repro from #38699 + +declare function strictEqual(actual: any, expected: T, message?: string | Error): asserts actual is T; +>strictEqual : (actual: any, expected: T, message?: string | Error | undefined) => asserts actual is T +>actual : any +>expected : T +>message : string | Error | undefined + +const b = false; +>b : false +>false : false + +strictEqual(false, b); +>strictEqual(false, b) : void +>strictEqual : (actual: any, expected: T, message?: string | Error | undefined) => asserts actual is T +>false : false +>b : false + +let b2 = b; +>b2 : boolean +>b : false + diff --git a/tests/cases/conformance/controlFlow/assertionTypePredicates1.ts b/tests/cases/conformance/controlFlow/assertionTypePredicates1.ts index cc90be3d84147..41b22bcba6208 100644 --- a/tests/cases/conformance/controlFlow/assertionTypePredicates1.ts +++ b/tests/cases/conformance/controlFlow/assertionTypePredicates1.ts @@ -193,3 +193,11 @@ function example1(things: Thing[]) { thing.good; } } + +// Repro from #38699 + +declare function strictEqual(actual: any, expected: T, message?: string | Error): asserts actual is T; + +const b = false; +strictEqual(false, b); +let b2 = b;