Record
/Field
Factories
#11
Locked
harrysolovay
started this conversation in
API Design
Replies: 2 comments 3 replies
-
Why not? JS does have a guaranteed property order. This is something that was standardized on ES2015 and even before then it was a de facto standard across JS engines. That's why |
Beta Was this translation helpful? Give feedback.
3 replies
-
Addressed in PR #17 – locking conversation |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Why is it that we define the shape of a record codec as follows?
At first glance, it seems strange that we must call
s.field
... couldn't we bypass this bloat?Why wouldn't the following work?
Unfortunately, the field order needs to be known for encoding. There's no way for us to reflect on this info [EDIT] well using a JS record. We could certainly allow fields to be defined via tuples:
The issue with this is that string literals "name" and "nickName" are widened to
string
.We must assert
as const
in order to get the literal typings of keys, which flow into the signature ofc
.It's very easy to forget to
as const
-ify––better to safeguard via the extra factoryfield
.Additionally, the
Field
type /field
factory is used elsewhere (tagged unions).Beta Was this translation helpful? Give feedback.
All reactions