-
-
Notifications
You must be signed in to change notification settings - Fork 162
Description
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
We have types, however they are not completely safe. I'd like to be able to ensure the exhaustive type check is run for case such as union where we want to handle where , but they also run an otherwise to prevent throwing of an error.
This means we can have the type checking where a type is partially complete.
Describe the solution you'd like
A clear and concise description of what you want to happen.
Add a new method exhaustiveOtherwise which does the exhaustive type check with a otherwise handler
const unit: 'days' | 'hours' = 'something'
match(unit)
.with('days', () => 'd')
.with('hours', () => 'h')
.exhaustiveOtherwise(() => 'never') // safety to prevent errorDescribe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Allow otherwise to chain onto the end of exhaustive
const unit: 'days' | 'hours' = 'something'
match(unit)
.with('days', () => 'd')
.with('hours', () => 'h')
.exhaustive()
.otherwise(() => 'never')Add validation such as zod to the data to handle incorrect data (hard as I would like to transition new code to be type safe without having to re-write all types)
Additional context
Add any other context or screenshots about the feature request here.