diff --git a/tests/baselines/reference/typeGuardsWithAny.js b/tests/baselines/reference/typeGuardsWithAny.js new file mode 100644 index 00000000000..628ea425185 --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithAny.js @@ -0,0 +1,12 @@ +//// [typeGuardsWithAny.ts] +var x: any = { p: 0 }; +if (x instanceof Object) { + x.p; // No error, type any is not narrowed +} + + +//// [typeGuardsWithAny.js] +var x = { p: 0 }; +if (x instanceof Object) { + x.p; // No error, type any is not narrowed +} diff --git a/tests/baselines/reference/typeGuardsWithAny.types b/tests/baselines/reference/typeGuardsWithAny.types new file mode 100644 index 00000000000..d79f813715b --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithAny.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts === +var x: any = { p: 0 }; +>x : any +>{ p: 0 } : { p: number; } +>p : number + +if (x instanceof Object) { +>x instanceof Object : boolean +>x : any +>Object : ObjectConstructor + + x.p; // No error, type any is not narrowed +>x.p : any +>x : any +>p : any +} + diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts new file mode 100644 index 00000000000..4e58d1a4acc --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts @@ -0,0 +1,4 @@ +var x: any = { p: 0 }; +if (x instanceof Object) { + x.p; // No error, type any is not narrowed +}