TypeScript/tests/baselines/reference/controlFlowTypeofObject.errors.txt
Anders Hejlsberg 5186ee3d1b
Track non-null unknown types in control flow analysis (#45575)
* Track non-null unknown types in CFA

* Add tests
2021-09-09 09:20:44 -07:00

77 lines
1.8 KiB
Plaintext

tests/cases/conformance/controlFlow/controlFlowTypeofObject.ts(66,13): error TS2345: Argument of type 'object | null' is not assignable to parameter of type 'object'.
Type 'null' is not assignable to type 'object'.
==== tests/cases/conformance/controlFlow/controlFlowTypeofObject.ts (1 errors) ====
declare function obj(x: object): void;
function f1(x: unknown) {
if (!x) {
return;
}
if (typeof x === 'object') {
obj(x);
}
}
function f2(x: unknown) {
if (x === null) {
return;
}
if (typeof x === 'object') {
obj(x);
}
}
function f3(x: unknown) {
if (x == null) {
return;
}
if (typeof x === 'object') {
obj(x);
}
}
function f4(x: unknown) {
if (x == undefined) {
return;
}
if (typeof x === 'object') {
obj(x);
}
}
function f5(x: unknown) {
if (!!true) {
if (!x) {
return;
}
}
else {
if (x === null) {
return;
}
}
if (typeof x === 'object') {
obj(x);
}
}
function f6(x: unknown) {
if (x === null) {
x;
}
else {
x;
if (typeof x === 'object') {
obj(x);
}
}
if (typeof x === 'object') {
obj(x); // Error
~
!!! error TS2345: Argument of type 'object | null' is not assignable to parameter of type 'object'.
!!! error TS2345: Type 'null' is not assignable to type 'object'.
}
}