Reputation: 11
interface TypeA {
optionalObj?: { prop: string }
}
const a: TypeA = {};
console.log(a.optionalObj.prop);
I want to find a Typescript-Eslint rule that will error on the line a.optionalObj.prop
, because optionalObj can be undefined.
Is there such a rule?
Upvotes: 1
Views: 1130
Reputation: 1075
This should be caught as a TS Error TS2532: Object is possibly 'undefined'.
If you're not seeing this error, fix your tsconfig.json
. You should turn strictNullChecks
on. Consider below flags.
"strict": true,
"alwaysStrict": true,
Upvotes: 1