errata
Aarktype
•Created by errata on 9/11/2024 in #questions
extracting redux-like actions from type.enumerated discriminated union
Trying unsuccessfully to convert some redux/reducer-like "action" object types to arktype:
Below is how I did the conversion. The
Extract
on the type.enumerated
results in a never
and I don't follow why.
If I define the action union type in vanilla TS (from the ark inferred types) the extract works as expected:
Am I holding it wrong?77 replies
Aarktype
•Created by errata on 9/10/2024 in #questions
alternative to nesting quotes in quotes for strings?
Needing to double + single quote everything feels really fiddly and clumsy, like, I feel like I don't my coworkers to see this code lest they judge me.
Is there a cleaner, alternative syntax/api?
24 replies
Aarktype
•Created by errata on 9/10/2024 in #questions
template literal/backtick string types e.g. type T = `type-${string}`
I can't see how to do in Ark:
I specifically want compile-time checking.
Tried to drop it in "1:1" style, but this doesn't work as-is:
nor did it work trying to use 'type' as a tagged template:
I did look in the docs but I don't believe it's there yet, and if it's in the tests I didn't spot it
Do I have to set it up as a custom string constraint so it'd be like
const UserId = type('string-userId')
?
IIUC this doesn't get the compile-time checking:
// Subtypes like 'email' are inferred like 'string' but provide additional validation at runtime. email: "string.email",
14 replies
Aarktype
•Created by errata on 9/9/2024 in #questions
Compile-time typesafe merge/and for data-only "traits"
I've evaluating introducing arktype to a typescript codebase, but I got stuck trying to use it to set up my POJO "traits" system. This is similar in concept to the Trait abstract class in
arktype/util
but this is data only; so far I've avoided the need to introduce any classes and I'm hoping to maintain this approach.
So I have a discriminated union that represents the different "traits" and the union members share a common shape (mainly references to other trait names), something along these lines:
I'm confused about how I would represent this setup in arktype in a typesafe manner? Or would you suggest an alternative way of representing this? I don't have any significant code written against these types so I'm open to rethinking this setup entirely.
I got stuck almost immediately as neither .and(...)
nor.merge(...)
will allow me to inherit compile-time type checking of requires
in my Trait
subtypes.
Please help! Thanks38 replies