Post

I feel the benefits are mostly in the signals: I use type errors when renaming or removing properties to know what code to update. If `obj?.a` is always valid, I lose those signals. New devs might use `?` as a crutch when property access fails. Typos like `obj?.a` vs `obj?.A` won’t be caught.

iirc in typescript object just stands for any non-primitive type, but doesn't convey any information about the object shape itself. though yeah, this case seems annoying you could do `v && 'a' in v && typeof v.a !== 'string'`. that `in` will intersect the object type with `{ a: unknown }`

I had this "problem" just last week. TS only allow property access for known properties, even when it's optional. In other words, even though `null?.a` is valid, TS is saying `null` doesn't have a known property `a`.

It's because the object type doesn't have a property called a. Using `in` will probably solve that like you said 👀

Right, I know how to work around it. But I am asking: Shouldn’t this be accepted by the type checker (because `null?.a` is perfectly valid)

Hey while you’re fixing TypeScript can you get them to let me skip writing `Promise<>` around the return types of functions that already have the `async` keyword?

This, except I tend to use use hasOwnProperty rather than in. Feels like I usually care about immediate properties in type guards, not inherited ones.