diff --git a/tests/baselines/reference/typeGuardsAsAssertions.js b/tests/baselines/reference/typeGuardsAsAssertions.js index f001a421c0b..84fc996c3ab 100644 --- a/tests/baselines/reference/typeGuardsAsAssertions.js +++ b/tests/baselines/reference/typeGuardsAsAssertions.js @@ -103,6 +103,23 @@ function f5(x: string | number) { } x; // string | number } + +function f6() { + let x: string | undefined | null; + x!.slice(); + x = ""; + x!.slice(); + x = undefined; + x!.slice(); + x = null; + x!.slice(); + x = undefined; + x!.slice(); + x = ""; + x!.slice(); + x = ""; + x!.slice(); +} //// [typeGuardsAsAssertions.js] @@ -194,3 +211,19 @@ function f5(x) { } x; // string | number } +function f6() { + var x; + x.slice(); + x = ""; + x.slice(); + x = undefined; + x.slice(); + x = null; + x.slice(); + x = undefined; + x.slice(); + x = ""; + x.slice(); + x = ""; + x.slice(); +} diff --git a/tests/baselines/reference/typeGuardsAsAssertions.symbols b/tests/baselines/reference/typeGuardsAsAssertions.symbols index a88580332c5..5079f3b8cb4 100644 --- a/tests/baselines/reference/typeGuardsAsAssertions.symbols +++ b/tests/baselines/reference/typeGuardsAsAssertions.symbols @@ -251,3 +251,65 @@ function f5(x: string | number) { >x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 95, 12)) } +function f6() { +>f6 : Symbol(f6, Decl(typeGuardsAsAssertions.ts, 103, 1)) + + let x: string | undefined | null; +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) + + x!.slice(); +>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) + + x = ""; +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) + + x!.slice(); +>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) + + x = undefined; +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) +>undefined : Symbol(undefined) + + x!.slice(); +>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) + + x = null; +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) + + x!.slice(); +>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) + + x = undefined; +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) +>undefined : Symbol(undefined) + + x!.slice(); +>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) + + x = ""; +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) + + x!.slice(); +>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) + + x = ""; +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) + + x!.slice(); +>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +} + diff --git a/tests/baselines/reference/typeGuardsAsAssertions.types b/tests/baselines/reference/typeGuardsAsAssertions.types index 9c4b5618d05..6ec84ada1f4 100644 --- a/tests/baselines/reference/typeGuardsAsAssertions.types +++ b/tests/baselines/reference/typeGuardsAsAssertions.types @@ -291,3 +291,95 @@ function f5(x: string | number) { >x : number | string } +function f6() { +>f6 : () => void + + let x: string | undefined | null; +>x : string | null | undefined +>null : null + + x!.slice(); +>x!.slice() : string +>x!.slice : (start?: number | undefined, end?: number | undefined) => string +>x! : string +>x : string | null | undefined +>slice : (start?: number | undefined, end?: number | undefined) => string + + x = ""; +>x = "" : string +>x : string | null | undefined +>"" : string + + x!.slice(); +>x!.slice() : string +>x!.slice : (start?: number | undefined, end?: number | undefined) => string +>x! : string +>x : string +>slice : (start?: number | undefined, end?: number | undefined) => string + + x = undefined; +>x = undefined : undefined +>x : string | null | undefined +>undefined : undefined + + x!.slice(); +>x!.slice() : string +>x!.slice : (start?: number | undefined, end?: number | undefined) => string +>x! : string +>x : string | null | undefined +>slice : (start?: number | undefined, end?: number | undefined) => string + + x = null; +>x = null : null +>x : string | null | undefined +>null : null + + x!.slice(); +>x!.slice() : string +>x!.slice : (start?: number | undefined, end?: number | undefined) => string +>x! : string +>x : string | null | undefined +>slice : (start?: number | undefined, end?: number | undefined) => string + + x = undefined; +>x = undefined : null | undefined +>x : string | null | undefined +>undefined : null | undefined +>null : null +>undefined : undefined + + x!.slice(); +>x!.slice() : string +>x!.slice : (start?: number | undefined, end?: number | undefined) => string +>x! : string +>x : string | null | undefined +>slice : (start?: number | undefined, end?: number | undefined) => string + + x = ""; +>x = "" : string | undefined +>x : string | null | undefined +>"" : string | undefined +>"" : string + + x!.slice(); +>x!.slice() : string +>x!.slice : (start?: number | undefined, end?: number | undefined) => string +>x! : string +>x : string | undefined +>slice : (start?: number | undefined, end?: number | undefined) => string + + x = ""; +>x = "" : string | null +>x : string | null | undefined +>"" : string | null +>null : null +>"" : string + + x!.slice(); +>x!.slice() : string +>x!.slice : (start?: number | undefined, end?: number | undefined) => string +>x! : string +>x : string | null +>slice : (start?: number | undefined, end?: number | undefined) => string +} + diff --git a/tests/cases/conformance/controlFlow/typeGuardsAsAssertions.ts b/tests/cases/conformance/controlFlow/typeGuardsAsAssertions.ts index d1a975c5017..912eaa64e80 100644 --- a/tests/cases/conformance/controlFlow/typeGuardsAsAssertions.ts +++ b/tests/cases/conformance/controlFlow/typeGuardsAsAssertions.ts @@ -103,3 +103,20 @@ function f5(x: string | number) { } x; // string | number } + +function f6() { + let x: string | undefined | null; + x!.slice(); + x = ""; + x!.slice(); + x = undefined; + x!.slice(); + x = null; + x!.slice(); + x = undefined; + x!.slice(); + x = ""; + x!.slice(); + x = ""; + x!.slice(); +}