mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Support properties of mapped types in assertion control flow analysis (#40482)
* Support properties of mapped types in assertion control flow analysis * Add regression test * Accept new baselines
This commit is contained in:
@@ -21103,6 +21103,12 @@ namespace ts {
|
||||
return getTypeOfSymbol(symbol);
|
||||
}
|
||||
if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) {
|
||||
if (getCheckFlags(symbol) & CheckFlags.Mapped) {
|
||||
const origin = (<MappedSymbol>symbol).syntheticOrigin;
|
||||
if (origin && getExplicitTypeOfSymbol(origin)) {
|
||||
return getTypeOfSymbol(symbol);
|
||||
}
|
||||
}
|
||||
const declaration = symbol.valueDeclaration;
|
||||
if (declaration) {
|
||||
if (isDeclarationWithExplicitTypeAnnotation(declaration)) {
|
||||
|
||||
@@ -318,4 +318,18 @@ tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(153,5): error TS
|
||||
this.throw()
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #40346
|
||||
|
||||
interface Services {
|
||||
panic(message: string): never;
|
||||
}
|
||||
|
||||
function foo(services: Readonly<Services>, s: string | null): string {
|
||||
if (s === null) {
|
||||
services.panic("ouch");
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,6 +247,20 @@ class SuperThrowable extends MyThrowable {
|
||||
this.throw()
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #40346
|
||||
|
||||
interface Services {
|
||||
panic(message: string): never;
|
||||
}
|
||||
|
||||
function foo(services: Readonly<Services>, s: string | null): string {
|
||||
if (s === null) {
|
||||
services.panic("ouch");
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [neverReturningFunctions1.js]
|
||||
@@ -467,6 +481,14 @@ var SuperThrowable = /** @class */ (function (_super) {
|
||||
};
|
||||
return SuperThrowable;
|
||||
}(MyThrowable));
|
||||
function foo(services, s) {
|
||||
if (s === null) {
|
||||
services.panic("ouch");
|
||||
}
|
||||
else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [neverReturningFunctions1.d.ts]
|
||||
|
||||
@@ -635,3 +635,34 @@ class SuperThrowable extends MyThrowable {
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #40346
|
||||
|
||||
interface Services {
|
||||
>Services : Symbol(Services, Decl(neverReturningFunctions1.ts, 247, 1))
|
||||
|
||||
panic(message: string): never;
|
||||
>panic : Symbol(Services.panic, Decl(neverReturningFunctions1.ts, 251, 20))
|
||||
>message : Symbol(message, Decl(neverReturningFunctions1.ts, 252, 10))
|
||||
}
|
||||
|
||||
function foo(services: Readonly<Services>, s: string | null): string {
|
||||
>foo : Symbol(foo, Decl(neverReturningFunctions1.ts, 253, 1))
|
||||
>services : Symbol(services, Decl(neverReturningFunctions1.ts, 255, 13))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --))
|
||||
>Services : Symbol(Services, Decl(neverReturningFunctions1.ts, 247, 1))
|
||||
>s : Symbol(s, Decl(neverReturningFunctions1.ts, 255, 42))
|
||||
|
||||
if (s === null) {
|
||||
>s : Symbol(s, Decl(neverReturningFunctions1.ts, 255, 42))
|
||||
|
||||
services.panic("ouch");
|
||||
>services.panic : Symbol(panic, Decl(neverReturningFunctions1.ts, 251, 20))
|
||||
>services : Symbol(services, Decl(neverReturningFunctions1.ts, 255, 13))
|
||||
>panic : Symbol(panic, Decl(neverReturningFunctions1.ts, 251, 20))
|
||||
|
||||
} else {
|
||||
return s;
|
||||
>s : Symbol(s, Decl(neverReturningFunctions1.ts, 255, 42))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -706,3 +706,35 @@ class SuperThrowable extends MyThrowable {
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #40346
|
||||
|
||||
interface Services {
|
||||
panic(message: string): never;
|
||||
>panic : (message: string) => never
|
||||
>message : string
|
||||
}
|
||||
|
||||
function foo(services: Readonly<Services>, s: string | null): string {
|
||||
>foo : (services: Readonly<Services>, s: string | null) => string
|
||||
>services : Readonly<Services>
|
||||
>s : string | null
|
||||
>null : null
|
||||
|
||||
if (s === null) {
|
||||
>s === null : boolean
|
||||
>s : string | null
|
||||
>null : null
|
||||
|
||||
services.panic("ouch");
|
||||
>services.panic("ouch") : never
|
||||
>services.panic : (message: string) => never
|
||||
>services : Readonly<Services>
|
||||
>panic : (message: string) => never
|
||||
>"ouch" : "ouch"
|
||||
|
||||
} else {
|
||||
return s;
|
||||
>s : string
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -250,3 +250,17 @@ class SuperThrowable extends MyThrowable {
|
||||
this.throw()
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #40346
|
||||
|
||||
interface Services {
|
||||
panic(message: string): never;
|
||||
}
|
||||
|
||||
function foo(services: Readonly<Services>, s: string | null): string {
|
||||
if (s === null) {
|
||||
services.panic("ouch");
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user