dibbo
dibbo
Aarktype
Created by dibbo on 8/29/2024 in #questions
Optional property with const string array
Hello, the following
const x = ["a", "b", "c"] as const;
const myType = type({
"optional?": type("===", ...x),
});
const x = ["a", "b", "c"] as const;
const myType = type({
"optional?": type("===", ...x),
});
is giving a
Only required keys may specify default values
Only required keys may specify default values
error. It's not really clear to me why - I assume the === operator is doing more than what I think. Is there a way to have an optional property be one of a string array in arktype? Or is what I'm after effectively indexed access expressions? Thanks
6 replies
Aarktype
Created by dibbo on 8/27/2024 in #questions
Indexed Access Types
Hello, is it possible to recreate the SizeValues type below in arktype?
const sizes = [
{ label: "Big", value: "100kg" },
{ label: "Medium", value: "50kg" },
{ label: "Small", value: "10kg" },
] as const;

type SizeValues = typeof sizes[number]['value'][]
const sizes = [
{ label: "Big", value: "100kg" },
{ label: "Medium", value: "50kg" },
{ label: "Small", value: "10kg" },
] as const;

type SizeValues = typeof sizes[number]['value'][]
9 replies
Aarktype
Created by dibbo on 8/16/2024 in #questions
Latest "keys:distilled" equivalent?
Hello, I started using ArkType a back in v1 and it has obviously come on leaps and bounds since then which is great to see. However, back in v1 you could do something like
export const loginPayload = type(
{
email: 'email',
password: '1<string<999',
},
{ keys: 'distilled' }
);
export const loginPayload = type(
{
email: 'email',
password: '1<string<999',
},
{ keys: 'distilled' }
);
and once you validated a payload against this you would only ever get an object with email/password keys. I'm wondering how to achieve a similar result with the latest version of the library. Thanks.
11 replies