Narrow matcher handler input based on data pattern
jasonkuhrt opened this issue · comments
Jason Kuhrt commented
Perceived Problem
From #83 (comment)
Realized an advanced type refinement feature we could have. But save for a future issue.
const Shape = Alge.data('Shape')
.record('Circle', { color: z.string().optional(), radius: z.number() })
.record('Square', { color: z.string().optional(), size: z.number() })
/* ... */
const result = Alge.match(shape).Circle({ color: 'red' }, (data) => data)
// 1
- The data that comes through should have
color: 'red'
instead ofcolor?: string
since the pattern match guarantees that.
Ideas / Proposed Solution(s)
Implement this.