Replies: 1 comment
-
The problem is that the morph can return the value There is a difference in JS between a key being present with the value The tsconfig setting The more precise option is unfortunately that you need to morph the top-level object top check for It may be possible to create a convenience syntax for this where returning some builtin symbol like |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I'm starting to need to do a little more than just the basics with arktype, eg, going from validation-only to transforming input to something simpler to deal with.
Specifically in my case I'm using arktype in the GUI to validate incoming messages from the server.
Our protocol is such that at startup the server sends a bunch of "complete" records and thereafter only sends deltas (just the changed fields).
The twist is that some of the fields in the "complete" record are optional. So naturally I'm modelling these with
'foo?': 'string'
(for example) in arktype.In order to "unset" an optional field in a delta message the server will send a
null
for that field. This is where I start getting into trouble, eg TS correctly complains about thisI noticed the morph syntax in the docs so though I might use that but I'm having some issues
The morph is doing what I want at runtime (see console log at the end), but at compile-time
typeof types.RecordDelta.infer
seems to produce an "input" type rather than the valid output type I would expect. That means I get a TypeScript error when trying to spread it into anotherRecord
value.Am I doing something wrong here?
A follow-on question I would have is that there are lot of optional fields in my real types and I'd rather not copy-paste the same (pure) boilerplate morph function for every one. Is there some way I can extract and make it generic over the input value, given that the input value's type is defined within the arktype
scope
?Beta Was this translation helpful? Give feedback.
All reactions