mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 20:51:43 -06:00
Add regression tests
This commit is contained in:
parent
b336c693ee
commit
29ae2b2cf1
84
tests/baselines/reference/discriminantsAndPrimitives.js
Normal file
84
tests/baselines/reference/discriminantsAndPrimitives.js
Normal file
@ -0,0 +1,84 @@
|
||||
//// [discriminantsAndPrimitives.ts]
|
||||
|
||||
// Repro from #10257 plus other tests
|
||||
|
||||
interface Foo {
|
||||
kind: "foo";
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Bar {
|
||||
kind: "bar";
|
||||
length: string;
|
||||
}
|
||||
|
||||
function f1(x: Foo | Bar | string) {
|
||||
if (typeof x !== 'string') {
|
||||
switch(x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: Foo | Bar | string | undefined) {
|
||||
if (typeof x === "object") {
|
||||
switch(x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f3(x: Foo | Bar | string | null) {
|
||||
if (x && typeof x !== "string") {
|
||||
switch(x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f4(x: Foo | Bar | string | number | null) {
|
||||
if (x && typeof x === "object") {
|
||||
switch(x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//// [discriminantsAndPrimitives.js]
|
||||
// Repro from #10257 plus other tests
|
||||
function f1(x) {
|
||||
if (typeof x !== 'string') {
|
||||
switch (x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
function f2(x) {
|
||||
if (typeof x === "object") {
|
||||
switch (x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
function f3(x) {
|
||||
if (x && typeof x !== "string") {
|
||||
switch (x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
function f4(x) {
|
||||
if (x && typeof x === "object") {
|
||||
switch (x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
117
tests/baselines/reference/discriminantsAndPrimitives.symbols
Normal file
117
tests/baselines/reference/discriminantsAndPrimitives.symbols
Normal file
@ -0,0 +1,117 @@
|
||||
=== tests/cases/compiler/discriminantsAndPrimitives.ts ===
|
||||
|
||||
// Repro from #10257 plus other tests
|
||||
|
||||
interface Foo {
|
||||
>Foo : Symbol(Foo, Decl(discriminantsAndPrimitives.ts, 0, 0))
|
||||
|
||||
kind: "foo";
|
||||
>kind : Symbol(Foo.kind, Decl(discriminantsAndPrimitives.ts, 3, 15))
|
||||
|
||||
name: string;
|
||||
>name : Symbol(Foo.name, Decl(discriminantsAndPrimitives.ts, 4, 16))
|
||||
}
|
||||
|
||||
interface Bar {
|
||||
>Bar : Symbol(Bar, Decl(discriminantsAndPrimitives.ts, 6, 1))
|
||||
|
||||
kind: "bar";
|
||||
>kind : Symbol(Bar.kind, Decl(discriminantsAndPrimitives.ts, 8, 15))
|
||||
|
||||
length: string;
|
||||
>length : Symbol(Bar.length, Decl(discriminantsAndPrimitives.ts, 9, 16))
|
||||
}
|
||||
|
||||
function f1(x: Foo | Bar | string) {
|
||||
>f1 : Symbol(f1, Decl(discriminantsAndPrimitives.ts, 11, 1))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 13, 12))
|
||||
>Foo : Symbol(Foo, Decl(discriminantsAndPrimitives.ts, 0, 0))
|
||||
>Bar : Symbol(Bar, Decl(discriminantsAndPrimitives.ts, 6, 1))
|
||||
|
||||
if (typeof x !== 'string') {
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 13, 12))
|
||||
|
||||
switch(x.kind) {
|
||||
>x.kind : Symbol(kind, Decl(discriminantsAndPrimitives.ts, 3, 15), Decl(discriminantsAndPrimitives.ts, 8, 15))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 13, 12))
|
||||
>kind : Symbol(kind, Decl(discriminantsAndPrimitives.ts, 3, 15), Decl(discriminantsAndPrimitives.ts, 8, 15))
|
||||
|
||||
case 'foo':
|
||||
x.name;
|
||||
>x.name : Symbol(Foo.name, Decl(discriminantsAndPrimitives.ts, 4, 16))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 13, 12))
|
||||
>name : Symbol(Foo.name, Decl(discriminantsAndPrimitives.ts, 4, 16))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: Foo | Bar | string | undefined) {
|
||||
>f2 : Symbol(f2, Decl(discriminantsAndPrimitives.ts, 20, 1))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 22, 12))
|
||||
>Foo : Symbol(Foo, Decl(discriminantsAndPrimitives.ts, 0, 0))
|
||||
>Bar : Symbol(Bar, Decl(discriminantsAndPrimitives.ts, 6, 1))
|
||||
|
||||
if (typeof x === "object") {
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 22, 12))
|
||||
|
||||
switch(x.kind) {
|
||||
>x.kind : Symbol(kind, Decl(discriminantsAndPrimitives.ts, 3, 15), Decl(discriminantsAndPrimitives.ts, 8, 15))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 22, 12))
|
||||
>kind : Symbol(kind, Decl(discriminantsAndPrimitives.ts, 3, 15), Decl(discriminantsAndPrimitives.ts, 8, 15))
|
||||
|
||||
case 'foo':
|
||||
x.name;
|
||||
>x.name : Symbol(Foo.name, Decl(discriminantsAndPrimitives.ts, 4, 16))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 22, 12))
|
||||
>name : Symbol(Foo.name, Decl(discriminantsAndPrimitives.ts, 4, 16))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f3(x: Foo | Bar | string | null) {
|
||||
>f3 : Symbol(f3, Decl(discriminantsAndPrimitives.ts, 29, 1))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 31, 12))
|
||||
>Foo : Symbol(Foo, Decl(discriminantsAndPrimitives.ts, 0, 0))
|
||||
>Bar : Symbol(Bar, Decl(discriminantsAndPrimitives.ts, 6, 1))
|
||||
|
||||
if (x && typeof x !== "string") {
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 31, 12))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 31, 12))
|
||||
|
||||
switch(x.kind) {
|
||||
>x.kind : Symbol(kind, Decl(discriminantsAndPrimitives.ts, 3, 15), Decl(discriminantsAndPrimitives.ts, 8, 15))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 31, 12))
|
||||
>kind : Symbol(kind, Decl(discriminantsAndPrimitives.ts, 3, 15), Decl(discriminantsAndPrimitives.ts, 8, 15))
|
||||
|
||||
case 'foo':
|
||||
x.name;
|
||||
>x.name : Symbol(Foo.name, Decl(discriminantsAndPrimitives.ts, 4, 16))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 31, 12))
|
||||
>name : Symbol(Foo.name, Decl(discriminantsAndPrimitives.ts, 4, 16))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f4(x: Foo | Bar | string | number | null) {
|
||||
>f4 : Symbol(f4, Decl(discriminantsAndPrimitives.ts, 38, 1))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 40, 12))
|
||||
>Foo : Symbol(Foo, Decl(discriminantsAndPrimitives.ts, 0, 0))
|
||||
>Bar : Symbol(Bar, Decl(discriminantsAndPrimitives.ts, 6, 1))
|
||||
|
||||
if (x && typeof x === "object") {
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 40, 12))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 40, 12))
|
||||
|
||||
switch(x.kind) {
|
||||
>x.kind : Symbol(kind, Decl(discriminantsAndPrimitives.ts, 3, 15), Decl(discriminantsAndPrimitives.ts, 8, 15))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 40, 12))
|
||||
>kind : Symbol(kind, Decl(discriminantsAndPrimitives.ts, 3, 15), Decl(discriminantsAndPrimitives.ts, 8, 15))
|
||||
|
||||
case 'foo':
|
||||
x.name;
|
||||
>x.name : Symbol(Foo.name, Decl(discriminantsAndPrimitives.ts, 4, 16))
|
||||
>x : Symbol(x, Decl(discriminantsAndPrimitives.ts, 40, 12))
|
||||
>name : Symbol(Foo.name, Decl(discriminantsAndPrimitives.ts, 4, 16))
|
||||
}
|
||||
}
|
||||
}
|
||||
141
tests/baselines/reference/discriminantsAndPrimitives.types
Normal file
141
tests/baselines/reference/discriminantsAndPrimitives.types
Normal file
@ -0,0 +1,141 @@
|
||||
=== tests/cases/compiler/discriminantsAndPrimitives.ts ===
|
||||
|
||||
// Repro from #10257 plus other tests
|
||||
|
||||
interface Foo {
|
||||
>Foo : Foo
|
||||
|
||||
kind: "foo";
|
||||
>kind : "foo"
|
||||
|
||||
name: string;
|
||||
>name : string
|
||||
}
|
||||
|
||||
interface Bar {
|
||||
>Bar : Bar
|
||||
|
||||
kind: "bar";
|
||||
>kind : "bar"
|
||||
|
||||
length: string;
|
||||
>length : string
|
||||
}
|
||||
|
||||
function f1(x: Foo | Bar | string) {
|
||||
>f1 : (x: string | Foo | Bar) => void
|
||||
>x : string | Foo | Bar
|
||||
>Foo : Foo
|
||||
>Bar : Bar
|
||||
|
||||
if (typeof x !== 'string') {
|
||||
>typeof x !== 'string' : boolean
|
||||
>typeof x : string
|
||||
>x : string | Foo | Bar
|
||||
>'string' : "string"
|
||||
|
||||
switch(x.kind) {
|
||||
>x.kind : "foo" | "bar"
|
||||
>x : Foo | Bar
|
||||
>kind : "foo" | "bar"
|
||||
|
||||
case 'foo':
|
||||
>'foo' : "foo"
|
||||
|
||||
x.name;
|
||||
>x.name : string
|
||||
>x : Foo
|
||||
>name : string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: Foo | Bar | string | undefined) {
|
||||
>f2 : (x: string | Foo | Bar | undefined) => void
|
||||
>x : string | Foo | Bar | undefined
|
||||
>Foo : Foo
|
||||
>Bar : Bar
|
||||
|
||||
if (typeof x === "object") {
|
||||
>typeof x === "object" : boolean
|
||||
>typeof x : string
|
||||
>x : string | Foo | Bar | undefined
|
||||
>"object" : "object"
|
||||
|
||||
switch(x.kind) {
|
||||
>x.kind : "foo" | "bar"
|
||||
>x : Foo | Bar
|
||||
>kind : "foo" | "bar"
|
||||
|
||||
case 'foo':
|
||||
>'foo' : "foo"
|
||||
|
||||
x.name;
|
||||
>x.name : string
|
||||
>x : Foo
|
||||
>name : string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f3(x: Foo | Bar | string | null) {
|
||||
>f3 : (x: string | Foo | Bar | null) => void
|
||||
>x : string | Foo | Bar | null
|
||||
>Foo : Foo
|
||||
>Bar : Bar
|
||||
>null : null
|
||||
|
||||
if (x && typeof x !== "string") {
|
||||
>x && typeof x !== "string" : boolean | "" | null
|
||||
>x : string | Foo | Bar | null
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | Foo | Bar
|
||||
>"string" : "string"
|
||||
|
||||
switch(x.kind) {
|
||||
>x.kind : "foo" | "bar"
|
||||
>x : Foo | Bar
|
||||
>kind : "foo" | "bar"
|
||||
|
||||
case 'foo':
|
||||
>'foo' : "foo"
|
||||
|
||||
x.name;
|
||||
>x.name : string
|
||||
>x : Foo
|
||||
>name : string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f4(x: Foo | Bar | string | number | null) {
|
||||
>f4 : (x: string | number | Foo | Bar | null) => void
|
||||
>x : string | number | Foo | Bar | null
|
||||
>Foo : Foo
|
||||
>Bar : Bar
|
||||
>null : null
|
||||
|
||||
if (x && typeof x === "object") {
|
||||
>x && typeof x === "object" : boolean | "" | 0 | null
|
||||
>x : string | number | Foo | Bar | null
|
||||
>typeof x === "object" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number | Foo | Bar
|
||||
>"object" : "object"
|
||||
|
||||
switch(x.kind) {
|
||||
>x.kind : "foo" | "bar"
|
||||
>x : Foo | Bar
|
||||
>kind : "foo" | "bar"
|
||||
|
||||
case 'foo':
|
||||
>'foo' : "foo"
|
||||
|
||||
x.name;
|
||||
>x.name : string
|
||||
>x : Foo
|
||||
>name : string
|
||||
}
|
||||
}
|
||||
}
|
||||
49
tests/cases/compiler/discriminantsAndPrimitives.ts
Normal file
49
tests/cases/compiler/discriminantsAndPrimitives.ts
Normal file
@ -0,0 +1,49 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
// Repro from #10257 plus other tests
|
||||
|
||||
interface Foo {
|
||||
kind: "foo";
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Bar {
|
||||
kind: "bar";
|
||||
length: string;
|
||||
}
|
||||
|
||||
function f1(x: Foo | Bar | string) {
|
||||
if (typeof x !== 'string') {
|
||||
switch(x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: Foo | Bar | string | undefined) {
|
||||
if (typeof x === "object") {
|
||||
switch(x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f3(x: Foo | Bar | string | null) {
|
||||
if (x && typeof x !== "string") {
|
||||
switch(x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f4(x: Foo | Bar | string | number | null) {
|
||||
if (x && typeof x === "object") {
|
||||
switch(x.kind) {
|
||||
case 'foo':
|
||||
x.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user