I'm curious to know what sets apart these two approaches when declaring the status
property. I understand that the second version maintains type safety, but how exactly does it achieve this?
export type OwnProps = {
id: number;
name: string;
status: 'draft' | 'completed';
};
and
status: Union(Literal('draft'), Literal('completed')),
For those interested, the library providing Union
, Literal
, and more can be found here: https://github.com/pelotom/runtypes