toolbox
toolbox copied to clipboard
isNull Guard on Nested Nullable Chain
Describe the bug
The isNull
guard is not working for the nested nullable chain.
Expected behavior
The following code should compile with the --strict
flag.
function f(x: {
foo: { bar: (string | undefined)[] | undefined } | undefined;
}) {
if (isNull(x.foo?.bar?.[0])) return;
x.foo.bar[0].toLowerCase();
}
Actual behavior
It throws the "Object is possibly 'undefined" error.
Seems it's not possible for now: https://github.com/microsoft/TypeScript/issues/34974
Fixed by https://github.com/microsoft/TypeScript/pull/55613