Nested morphs not being applied
As seen in the code comments, I would expect the nested morph to be applied to the value, maybe I am doing something wrong but can't figure out how to implement the desired behaviour. Thanks for any help ๐
9 Replies
In terms of the types, a lot of this look good. One issue you will run into is that
.default
returns a definition that can be referenced in an object, not a type itself, so you'll need to update the return type there to reflect that (it should be something like [Type<T | null | undefined>, "=", null]
).
https://arktype.io/docs/objects#properties-defaultable
In terms of the runtime behavior, I'd need a bit of time to delve into this and understand what is going on- it does look like there could be an issue with nested defaults and pipes. Would you be able to log a GitHub issue with this repro?Thanks for the insight
ark playground is unable to compile this code, are there any other preferences for a repro or a github repo would work?
Ahh damn, yeah you can just post a code snippet in the issue honestly it seems pretty self-contained
I was looking at the structure of the type which seems right so it seems related to the traversal logic where morphs are applied
Thanks again for looking into this: https://github.com/arktypeio/arktype/issues/1509
GitHub
[Bug] Nested morphs not being applied correctly ยท Issue #1509 ยท a...
Report a bug ๐ Search Terms nested morphs, default, pipe ๐งฉ Context ArkType version: 2.1.22 TypeScript version (5.1+): 5.9.2 Other context you think may be relevant (JS flavor, OS, etc.): System: OS...
in the meantime do you have any workarounds I might be able to use?
this only happens with defaults I think
I'm going to be travelling for a couple weeks but I will try to take a look sometime when I get back.
Thanks, have nice travels โค๏ธ
The best workaround then would probably be to create a version of the utility that morphs the top-level object to add the values you need instead of relying on
default
directly if you've found that to be the issue.
Maybe a little trickier to get a clean API there but seems like you're pretty good with generics so I have faith :Prayge:
Definitely to want to revisit this case to ensure it works though as just being able to create those props directly does feel a lot cleanergot it, yeah that was my original code, that one requires manually passing in the optional keys though, but in any case, thanks for the help and insights, love the library