Skip to content

Commit 9f30d9f

Browse files
committed
Adding test
1 parent 5edf726 commit 9f30d9f

File tree

4 files changed

+204
-0
lines changed

4 files changed

+204
-0
lines changed

tests/baselines/reference/typeGuardsAsAssertions.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ function f5(x: string | number) {
103103
}
104104
x; // string | number
105105
}
106+
107+
function f6() {
108+
let x: string | undefined | null;
109+
x!.slice();
110+
x = "";
111+
x!.slice();
112+
x = undefined;
113+
x!.slice();
114+
x = null;
115+
x!.slice();
116+
x = <undefined | null>undefined;
117+
x!.slice();
118+
x = <string | undefined>"";
119+
x!.slice();
120+
x = <string | null>"";
121+
x!.slice();
122+
}
106123

107124

108125
//// [typeGuardsAsAssertions.js]
@@ -194,3 +211,19 @@ function f5(x) {
194211
}
195212
x; // string | number
196213
}
214+
function f6() {
215+
var x;
216+
x.slice();
217+
x = "";
218+
x.slice();
219+
x = undefined;
220+
x.slice();
221+
x = null;
222+
x.slice();
223+
x = undefined;
224+
x.slice();
225+
x = "";
226+
x.slice();
227+
x = "";
228+
x.slice();
229+
}

tests/baselines/reference/typeGuardsAsAssertions.symbols

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,65 @@ function f5(x: string | number) {
251251
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 95, 12))
252252
}
253253

254+
function f6() {
255+
>f6 : Symbol(f6, Decl(typeGuardsAsAssertions.ts, 103, 1))
256+
257+
let x: string | undefined | null;
258+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
259+
260+
x!.slice();
261+
>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
262+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
263+
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
264+
265+
x = "";
266+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
267+
268+
x!.slice();
269+
>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
270+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
271+
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
272+
273+
x = undefined;
274+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
275+
>undefined : Symbol(undefined)
276+
277+
x!.slice();
278+
>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
279+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
280+
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
281+
282+
x = null;
283+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
284+
285+
x!.slice();
286+
>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
287+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
288+
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
289+
290+
x = <undefined | null>undefined;
291+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
292+
>undefined : Symbol(undefined)
293+
294+
x!.slice();
295+
>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
296+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
297+
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
298+
299+
x = <string | undefined>"";
300+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
301+
302+
x!.slice();
303+
>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
304+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
305+
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
306+
307+
x = <string | null>"";
308+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
309+
310+
x!.slice();
311+
>x!.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
312+
>x : Symbol(x, Decl(typeGuardsAsAssertions.ts, 106, 7))
313+
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
314+
}
315+

tests/baselines/reference/typeGuardsAsAssertions.types

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,95 @@ function f5(x: string | number) {
291291
>x : number | string
292292
}
293293

294+
function f6() {
295+
>f6 : () => void
296+
297+
let x: string | undefined | null;
298+
>x : string | null | undefined
299+
>null : null
300+
301+
x!.slice();
302+
>x!.slice() : string
303+
>x!.slice : (start?: number | undefined, end?: number | undefined) => string
304+
>x! : string
305+
>x : string | null | undefined
306+
>slice : (start?: number | undefined, end?: number | undefined) => string
307+
308+
x = "";
309+
>x = "" : string
310+
>x : string | null | undefined
311+
>"" : string
312+
313+
x!.slice();
314+
>x!.slice() : string
315+
>x!.slice : (start?: number | undefined, end?: number | undefined) => string
316+
>x! : string
317+
>x : string
318+
>slice : (start?: number | undefined, end?: number | undefined) => string
319+
320+
x = undefined;
321+
>x = undefined : undefined
322+
>x : string | null | undefined
323+
>undefined : undefined
324+
325+
x!.slice();
326+
>x!.slice() : string
327+
>x!.slice : (start?: number | undefined, end?: number | undefined) => string
328+
>x! : string
329+
>x : string | null | undefined
330+
>slice : (start?: number | undefined, end?: number | undefined) => string
331+
332+
x = null;
333+
>x = null : null
334+
>x : string | null | undefined
335+
>null : null
336+
337+
x!.slice();
338+
>x!.slice() : string
339+
>x!.slice : (start?: number | undefined, end?: number | undefined) => string
340+
>x! : string
341+
>x : string | null | undefined
342+
>slice : (start?: number | undefined, end?: number | undefined) => string
343+
344+
x = <undefined | null>undefined;
345+
>x = <undefined | null>undefined : null | undefined
346+
>x : string | null | undefined
347+
><undefined | null>undefined : null | undefined
348+
>null : null
349+
>undefined : undefined
350+
351+
x!.slice();
352+
>x!.slice() : string
353+
>x!.slice : (start?: number | undefined, end?: number | undefined) => string
354+
>x! : string
355+
>x : string | null | undefined
356+
>slice : (start?: number | undefined, end?: number | undefined) => string
357+
358+
x = <string | undefined>"";
359+
>x = <string | undefined>"" : string | undefined
360+
>x : string | null | undefined
361+
><string | undefined>"" : string | undefined
362+
>"" : string
363+
364+
x!.slice();
365+
>x!.slice() : string
366+
>x!.slice : (start?: number | undefined, end?: number | undefined) => string
367+
>x! : string
368+
>x : string | undefined
369+
>slice : (start?: number | undefined, end?: number | undefined) => string
370+
371+
x = <string | null>"";
372+
>x = <string | null>"" : string | null
373+
>x : string | null | undefined
374+
><string | null>"" : string | null
375+
>null : null
376+
>"" : string
377+
378+
x!.slice();
379+
>x!.slice() : string
380+
>x!.slice : (start?: number | undefined, end?: number | undefined) => string
381+
>x! : string
382+
>x : string | null
383+
>slice : (start?: number | undefined, end?: number | undefined) => string
384+
}
385+

tests/cases/conformance/controlFlow/typeGuardsAsAssertions.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,20 @@ function f5(x: string | number) {
103103
}
104104
x; // string | number
105105
}
106+
107+
function f6() {
108+
let x: string | undefined | null;
109+
x!.slice();
110+
x = "";
111+
x!.slice();
112+
x = undefined;
113+
x!.slice();
114+
x = null;
115+
x!.slice();
116+
x = <undefined | null>undefined;
117+
x!.slice();
118+
x = <string | undefined>"";
119+
x!.slice();
120+
x = <string | null>"";
121+
x!.slice();
122+
}

0 commit comments

Comments
 (0)