Roamin
Roamin
Aarktype
Created by Roamin on 9/1/2024 in #questions
Best way to pass `Type` around
I changed it to run: (args: Type<inferAmbient<def>>["infer"]) => void; and it's working perfectly! Thanks for your help 😉
9 replies
Aarktype
Created by Roamin on 9/1/2024 in #questions
Best way to pass `Type` around
Thanks! If I were to change your defineCommand definiton to the one below, how would you define args so that its props types all have the inferred types?
function defineCommand<const def>(o: {
arguments: validateAmbient<def>;
run: (args: ???<def>) => void;
}) { }
function defineCommand<const def>(o: {
arguments: validateAmbient<def>;
run: (args: ???<def>) => void;
}) { }
I tried using inferAmbient, but narrows/morphs don't get "fully" inferred:
function defineCommand<const def>(o: {
arguments: validateAmbient<def>;
run: (args: inferAmbient<def>) => void;
}) {}

defineCommand({
arguments: {
first: "boolean",
default: "number = 123",
number: ["string", "=>", parseFloat],
"optional?": "string",
},
run(args) {
args;
// ^?
// (parameter) args: {
// first: boolean;
// default: (In?: number | undefined) => Default<123>;
// number: (In: string) => Out<number>;
// optional?: string | undefined;
// }
},
});
function defineCommand<const def>(o: {
arguments: validateAmbient<def>;
run: (args: inferAmbient<def>) => void;
}) {}

defineCommand({
arguments: {
first: "boolean",
default: "number = 123",
number: ["string", "=>", parseFloat],
"optional?": "string",
},
run(args) {
args;
// ^?
// (parameter) args: {
// first: boolean;
// default: (In?: number | undefined) => Default<123>;
// number: (In: string) => Out<number>;
// optional?: string | undefined;
// }
},
});
9 replies
Aarktype
Created by Roamin on 9/1/2024 in #questions
Best way to pass `Type` around
The first version of the ArkType type's definition was actually type ArkType = Type, but for some reason narrows and morphs weren't passing the check T extends Type, so I had to use type ArkType = Type | Type<(_: any) => any>; I guess my question is about what would be the best way to pass Type around and extract the out/infer type? I'm fairly new to arktype and I may not have made the best choice here 🙂
9 replies