sindresorhus / type-fest

A collection of essential TypeScript types
Creative Commons Zero v1.0 Universal
14.41k stars 547 forks source link

Proposal: ReadonlyDate #963

Open sindresorhus opened 1 month ago

sindresorhus commented 1 month ago

Type description + examples

Would be annoying as input, but can be useful as a return value.

Type source

type ReadonlyDate = Omit<Date, `set${string}`>;

Search existing types and issues first

Upvote & Fund

Fund with Polar

fregante commented 1 month ago

Would be annoying as input

I think that kills it, because you can't assign this return value to anything that accepts Date, so it's barely "read-only". Having to use date as Date every time isn't great

voxpelli commented 1 month ago

Would probably be better to do this as a typed readonly wrapper / proxy to Date with a way to get a full date.

const foo: ReadonlyDate = new ReadonlyDate();
const bar: Date = foo.getDate();