diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.js b/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.js new file mode 100644 index 0000000000..0e7ada149d --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.js @@ -0,0 +1,73 @@ +//// [typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts] +class C { private p: string }; + +var strOrNum: string | number; +var strOrBool: string | boolean; +var numOrBool: number | boolean +var strOrC: string | C; + +// typeof x == s has not effect on typeguard +if (typeof strOrNum == "string") { + var r1 = strOrNum; // string | number +} +else { + var r1 = strOrNum; // string | number +} + +if (typeof strOrBool == "boolean") { + var r2 = strOrBool; // string | boolean +} +else { + var r2 = strOrBool; // string | boolean +} + +if (typeof numOrBool == "number") { + var r3 = numOrBool; // number | boolean +} +else { + var r3 = numOrBool; // number | boolean +} + +if (typeof strOrC == "Object") { + var r4 = strOrC; // string | C +} +else { + var r4 = strOrC; // string | C +} + +//// [typeGuardOfFormTypeOfEqualEqualHasNoEffect.js] +var C = (function () { + function C() { + } + return C; +})(); +; +var strOrNum; +var strOrBool; +var numOrBool; +var strOrC; +// typeof x == s has not effect on typeguard +if (typeof strOrNum == "string") { + var r1 = strOrNum; // string | number +} +else { + var r1 = strOrNum; // string | number +} +if (typeof strOrBool == "boolean") { + var r2 = strOrBool; // string | boolean +} +else { + var r2 = strOrBool; // string | boolean +} +if (typeof numOrBool == "number") { + var r3 = numOrBool; // number | boolean +} +else { + var r3 = numOrBool; // number | boolean +} +if (typeof strOrC == "Object") { + var r4 = strOrC; // string | C +} +else { + var r4 = strOrC; // string | C +} diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.types b/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.types new file mode 100644 index 0000000000..14d4cd61c5 --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.types @@ -0,0 +1,78 @@ +=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts === +class C { private p: string }; +>C : C +>p : string + +var strOrNum: string | number; +>strOrNum : string | number + +var strOrBool: string | boolean; +>strOrBool : string | boolean + +var numOrBool: number | boolean +>numOrBool : number | boolean + +var strOrC: string | C; +>strOrC : string | C +>C : C + +// typeof x == s has not effect on typeguard +if (typeof strOrNum == "string") { +>typeof strOrNum == "string" : boolean +>typeof strOrNum : string +>strOrNum : string | number + + var r1 = strOrNum; // string | number +>r1 : string | number +>strOrNum : string | number +} +else { + var r1 = strOrNum; // string | number +>r1 : string | number +>strOrNum : string | number +} + +if (typeof strOrBool == "boolean") { +>typeof strOrBool == "boolean" : boolean +>typeof strOrBool : string +>strOrBool : string | boolean + + var r2 = strOrBool; // string | boolean +>r2 : string | boolean +>strOrBool : string | boolean +} +else { + var r2 = strOrBool; // string | boolean +>r2 : string | boolean +>strOrBool : string | boolean +} + +if (typeof numOrBool == "number") { +>typeof numOrBool == "number" : boolean +>typeof numOrBool : string +>numOrBool : number | boolean + + var r3 = numOrBool; // number | boolean +>r3 : number | boolean +>numOrBool : number | boolean +} +else { + var r3 = numOrBool; // number | boolean +>r3 : number | boolean +>numOrBool : number | boolean +} + +if (typeof strOrC == "Object") { +>typeof strOrC == "Object" : boolean +>typeof strOrC : string +>strOrC : string | C + + var r4 = strOrC; // string | C +>r4 : string | C +>strOrC : string | C +} +else { + var r4 = strOrC; // string | C +>r4 : string | C +>strOrC : string | C +} diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.js b/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.js new file mode 100644 index 0000000000..6a9851b51a --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.js @@ -0,0 +1,73 @@ +//// [typeGuardOfFormTypeOfNotEqualHasNoEffect.ts] +class C { private p: string }; + +var strOrNum: string | number; +var strOrBool: string | boolean; +var numOrBool: number | boolean +var strOrC: string | C; + +// typeof x != s has not effect on typeguard +if (typeof strOrNum != "string") { + var r1 = strOrNum; // string | number +} +else { + var r1 = strOrNum; // string | number +} + +if (typeof strOrBool != "boolean") { + var r2 = strOrBool; // string | boolean +} +else { + var r2 = strOrBool; // string | boolean +} + +if (typeof numOrBool != "number") { + var r3 = numOrBool; // number | boolean +} +else { + var r3 = numOrBool; // number | boolean +} + +if (typeof strOrC != "Object") { + var r4 = strOrC; // string | C +} +else { + var r4 = strOrC; // string | C +} + +//// [typeGuardOfFormTypeOfNotEqualHasNoEffect.js] +var C = (function () { + function C() { + } + return C; +})(); +; +var strOrNum; +var strOrBool; +var numOrBool; +var strOrC; +// typeof x != s has not effect on typeguard +if (typeof strOrNum != "string") { + var r1 = strOrNum; // string | number +} +else { + var r1 = strOrNum; // string | number +} +if (typeof strOrBool != "boolean") { + var r2 = strOrBool; // string | boolean +} +else { + var r2 = strOrBool; // string | boolean +} +if (typeof numOrBool != "number") { + var r3 = numOrBool; // number | boolean +} +else { + var r3 = numOrBool; // number | boolean +} +if (typeof strOrC != "Object") { + var r4 = strOrC; // string | C +} +else { + var r4 = strOrC; // string | C +} diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.types b/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.types new file mode 100644 index 0000000000..322799f6f7 --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.types @@ -0,0 +1,78 @@ +=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasNoEffect.ts === +class C { private p: string }; +>C : C +>p : string + +var strOrNum: string | number; +>strOrNum : string | number + +var strOrBool: string | boolean; +>strOrBool : string | boolean + +var numOrBool: number | boolean +>numOrBool : number | boolean + +var strOrC: string | C; +>strOrC : string | C +>C : C + +// typeof x != s has not effect on typeguard +if (typeof strOrNum != "string") { +>typeof strOrNum != "string" : boolean +>typeof strOrNum : string +>strOrNum : string | number + + var r1 = strOrNum; // string | number +>r1 : string | number +>strOrNum : string | number +} +else { + var r1 = strOrNum; // string | number +>r1 : string | number +>strOrNum : string | number +} + +if (typeof strOrBool != "boolean") { +>typeof strOrBool != "boolean" : boolean +>typeof strOrBool : string +>strOrBool : string | boolean + + var r2 = strOrBool; // string | boolean +>r2 : string | boolean +>strOrBool : string | boolean +} +else { + var r2 = strOrBool; // string | boolean +>r2 : string | boolean +>strOrBool : string | boolean +} + +if (typeof numOrBool != "number") { +>typeof numOrBool != "number" : boolean +>typeof numOrBool : string +>numOrBool : number | boolean + + var r3 = numOrBool; // number | boolean +>r3 : number | boolean +>numOrBool : number | boolean +} +else { + var r3 = numOrBool; // number | boolean +>r3 : number | boolean +>numOrBool : number | boolean +} + +if (typeof strOrC != "Object") { +>typeof strOrC != "Object" : boolean +>typeof strOrC : string +>strOrC : string | C + + var r4 = strOrC; // string | C +>r4 : string | C +>strOrC : string | C +} +else { + var r4 = strOrC; // string | C +>r4 : string | C +>strOrC : string | C +} diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts new file mode 100644 index 0000000000..03d650ad62 --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts @@ -0,0 +1,35 @@ +class C { private p: string }; + +var strOrNum: string | number; +var strOrBool: string | boolean; +var numOrBool: number | boolean +var strOrC: string | C; + +// typeof x == s has not effect on typeguard +if (typeof strOrNum == "string") { + var r1 = strOrNum; // string | number +} +else { + var r1 = strOrNum; // string | number +} + +if (typeof strOrBool == "boolean") { + var r2 = strOrBool; // string | boolean +} +else { + var r2 = strOrBool; // string | boolean +} + +if (typeof numOrBool == "number") { + var r3 = numOrBool; // number | boolean +} +else { + var r3 = numOrBool; // number | boolean +} + +if (typeof strOrC == "Object") { + var r4 = strOrC; // string | C +} +else { + var r4 = strOrC; // string | C +} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasNoEffect.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasNoEffect.ts new file mode 100644 index 0000000000..19d5495fcb --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasNoEffect.ts @@ -0,0 +1,35 @@ +class C { private p: string }; + +var strOrNum: string | number; +var strOrBool: string | boolean; +var numOrBool: number | boolean +var strOrC: string | C; + +// typeof x != s has not effect on typeguard +if (typeof strOrNum != "string") { + var r1 = strOrNum; // string | number +} +else { + var r1 = strOrNum; // string | number +} + +if (typeof strOrBool != "boolean") { + var r2 = strOrBool; // string | boolean +} +else { + var r2 = strOrBool; // string | boolean +} + +if (typeof numOrBool != "number") { + var r3 = numOrBool; // number | boolean +} +else { + var r3 = numOrBool; // number | boolean +} + +if (typeof strOrC != "Object") { + var r4 = strOrC; // string | C +} +else { + var r4 = strOrC; // string | C +} \ No newline at end of file