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?45 Replies
Enumerated is array.includes, not a union
You need A1.or(A2)
Lemme actual rewrite your code
are you sure? because when I look at the resulting type of the infer on the type.enumerated
type ArkAction = type.infer<typeof ArkAction>
it looks like this:
https://github.com/arktypeio/arktype/blob/da2f08d559e7c9a8e95ca513227a1496f9be3041/ark/type/__tests__/type.test.ts#L126-L130hm, it does work
It's for
const typeValue = type(['===', 'ACTION_1', 'ACTION_2'])
i.e. for enumsyeah i basically have an enum though, right?
No
A enum of
let a = {}, b = []
is [a, b].includes(v)
, not [{}, []].includes(v)
as different object instances are not equalahh
ahhh
right
===
ok got it
So you are checking if your object is one of two ArkType instances lol
ahhh
ok ok, thank you that makes sense
BTW how do you think it should be named?
The make union one and the make array of values one?
I do not feel like it's named perfectly so what would you guess they are named if you never used ArkType?
May be more then one variant
May be inspired by other validators
enumerated is ok, that's actually how I assumed it worked previously
and
.or
is fine as well
totally
though I'm not keen on the chaining@ssalbdivad we need
type.oneOf
or type.discriminatedUnion
equivalent as I expect peoples to want a way to avoid .or
chainingtype.union
?