jasonkuhrt / alge

Type safe library for creating Algebraic Data Types (ADTs) in TypeScript. 🌱

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Narrow matcher handler input based on data pattern

jasonkuhrt opened this issue · comments

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
  1. The data that comes through should have color: 'red' instead of color?: string since the pattern match guarantees that.

Ideas / Proposed Solution(s)

Implement this.