Need help specifying type Z that can either be type X or Y, where type X and Y share the same properties but type Y constrains values. Look at the following example:
type Role = 'user' | 'admin'
type Y = { role: Role, id: string | number }
type Z = { role: 'admin', id: string }
type X = Y | Z
This all works great, but if I change type Y specification (e.g., add a new field), TypeScript won't lint and warn that type Z must also be updated. Furthermore, while filing type Z, I can't get auto-complete of known fields in type Y.
Does anybody know a way to create this boundary constraint between type Y and Z?