mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
//// [tests/cases/conformance/types/any/narrowFromAnyWithInstanceof.ts] ////
|
|
|
|
//// [narrowFromAnyWithInstanceof.ts]
|
|
declare var x: any;
|
|
|
|
if (x instanceof Function) { // 'any' is not narrowed when target type is 'Function'
|
|
x();
|
|
x(1, 2, 3);
|
|
x("hello!");
|
|
x.prop;
|
|
}
|
|
|
|
if (x instanceof Object) { // 'any' is not narrowed when target type is 'Object'
|
|
x.method();
|
|
x();
|
|
}
|
|
|
|
if (x instanceof Error) { // 'any' is narrowed to types other than 'Function'/'Object'
|
|
x.message;
|
|
x.mesage;
|
|
}
|
|
|
|
if (x instanceof Date) {
|
|
x.getDate();
|
|
x.getHuors();
|
|
}
|
|
|
|
|
|
//// [narrowFromAnyWithInstanceof.js]
|
|
"use strict";
|
|
if (x instanceof Function) { // 'any' is not narrowed when target type is 'Function'
|
|
x();
|
|
x(1, 2, 3);
|
|
x("hello!");
|
|
x.prop;
|
|
}
|
|
if (x instanceof Object) { // 'any' is not narrowed when target type is 'Object'
|
|
x.method();
|
|
x();
|
|
}
|
|
if (x instanceof Error) { // 'any' is narrowed to types other than 'Function'/'Object'
|
|
x.message;
|
|
x.mesage;
|
|
}
|
|
if (x instanceof Date) {
|
|
x.getDate();
|
|
x.getHuors();
|
|
}
|