````js
// @flow
/* flowlint
type Shape = $ObjMap(param: T) => T | void | null>;
type B = { a: { b: 1 } };
declare var obj: Shape;
obj.a?.b; // Does not error, correctly.
declare var obj2: $Shape;
obj2.a?.b; // Should not error but does.
````
[try flow]
One solution might be to replace the $Shape utility with one implemented using $ObjMap instead
There is better one #7643
declare var obj2: $Shape<B>;
obj2.a?.b; // Should not error but does.
Yeah, $Shape doesn't really make fields optional, and it is kinda expected behaviour. It has been discussed many times. See #7730, #7566. Also #7316, #5702, #6039, #6796 (open issues).
const a: $Shape<{ a: 1, b: 2 }> = { a: 1 } // no error
a.b * 2 // no error
I guess, what $Shape really does is something like reversing direction of width subtyping (and that's unsafe). You can use $Rest<T, {}> or {...T} instead.
This can be closed as a duplicate, I think.
Good info @Bannerets. Will close as duplicate.
Duplicate of #5702