DZakh / rescript-schema

🧬 The fastest parser in the entire JavaScript ecosystem with a focus on small bundle size and top-notch DX
MIT License
162 stars 7 forks source link

Intersection Types #60

Closed justin0mcateer closed 1 year ago

justin0mcateer commented 1 year ago

Apologies in advance if this is an ignorant question, I am not really very familiar with Rescript, I am trying out using the library via the TypeScript API.

Is there anyway to re-use parts of the schema, which are not themselves fields, eg a group of fields? In my mind this would be analogous to a mix-in or how you might use 'intersection' algebraic types in TypeScript

DZakh commented 1 year ago

Could you provide an example using https://github.com/colinhacks/zod. Even if it's not possible with the current API, I can add support for this in the next version.

DZakh commented 1 year ago

Are you referring to something like this? https://github.com/colinhacks/zod#intersections

justin0mcateer commented 1 year ago

Yes, precisely.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Dmitry Zakharov @.> Sent: Monday, July 3, 2023 3:56:59 PM To: DZakh/rescript-struct @.> Cc: justin0mcateer @.>; Author @.> Subject: Re: [DZakh/rescript-struct] Intersection Types (Issue #60)

Are you referring to something like this? https://github.com/colinhacks/zod#intersections

— Reply to this email directly, view it on GitHubhttps://github.com/DZakh/rescript-struct/issues/60#issuecomment-1619143194, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAT4Q7MZOVNOYPWIHWAMEYDXOMWZXANCNFSM6AAAAAAZ4UUWMA. You are receiving this because you authored the thread.Message ID: @.***>

DZakh commented 1 year ago

I'll add it in the V5.1

DZakh commented 1 year ago

I've added it as S.merge in the V5.1 release. Let me know if you need anything else. Starting from V5.1 I've decided to make JS/TS API a legit target for rescript-struct.