type AnyObject = { [key: string]: AnyObject | undefined; } const a = {} as AnyObject console.log(a.b?.c) // This is fine console.log(a.b.c) // This gives a possibly undefined error
You can try it on the TS Playground here