
test.ts :
import {resultify} from "rustic-error";
type a = {
bar(): string;
}
type b = {
foo: a|null
}
const bFoo: b = {
foo: {
bar(): string {
return 'Joe doe'
}
}
}
if (bFoo.foo !== null) {
const bar1 = bFoo.foo.bar();
const bar2 = resultify(() => bFoo.foo.bar());
}
tsconfig.json :
{
"compilerOptions": {
"target": "es2022",
"module": "commonjs",
"strict": true,
}
}
solution that can remove error, but not pratical :
if (bFoo.foo !== null) {
const bar1 = bFoo.foo.bar();
const foo = bFoo.foo
const bar2 = resultify(() => foo.bar());
}
test.ts :
tsconfig.json :
{ "compilerOptions": { "target": "es2022", "module": "commonjs", "strict": true, } }solution that can remove error, but not pratical :