Defining and inferring a generic type defined inside a scope

I'm brand new to this library so I'm sorry if I'm doing something dumb, but I'm not sure how I can define a generic inside a scope. My broken code looks like this:
export const randomScope = scope({
foo: {
bar: "'biz'",
},
request: type("<t>", {
kind: "foo",
payload: "t",
}),
}).export();

export type Test = typeof randomScope.request.infer;
export const randomScope = scope({
foo: {
bar: "'biz'",
},
request: type("<t>", {
kind: "foo",
payload: "t",
}),
}).export();

export type Test = typeof randomScope.request.infer;
And I have the following errors:
No overload matches this call.
Overload 1 of 3, '(params: "<t>", def: validateObjectLiteral<{ readonly kind: "foo"; readonly payload: "t"; }, {}, baseGenericConstraints<[["t", unknown]]>>): Generic<...>', gave the following error.
Type '"foo"' is not assignable to type '"'foo' is unresolvable "'.
Overload 2 of 3, '(_0: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "Key" | "Record" | "Date" | "Array" | "false" | "never" | "null" | "true" | "unknown" | "keyof" | ... 24 more ... | "this", _1: IndexOneOperator): Type<...>', gave the following error.
Argument of type '"<t>"' is not assignable to parameter of type '"string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "Key" | "Record" | "Date" | "Array" | "false" | "never" | "null" | "true" | "unknown" | "keyof" | ... 24 more ... | "this"'.ts(2769)
No overload matches this call.
Overload 1 of 3, '(params: "<t>", def: validateObjectLiteral<{ readonly kind: "foo"; readonly payload: "t"; }, {}, baseGenericConstraints<[["t", unknown]]>>): Generic<...>', gave the following error.
Type '"foo"' is not assignable to type '"'foo' is unresolvable "'.
Overload 2 of 3, '(_0: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "Key" | "Record" | "Date" | "Array" | "false" | "never" | "null" | "true" | "unknown" | "keyof" | ... 24 more ... | "this", _1: IndexOneOperator): Type<...>', gave the following error.
Argument of type '"<t>"' is not assignable to parameter of type '"string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "Key" | "Record" | "Date" | "Array" | "false" | "never" | "null" | "true" | "unknown" | "keyof" | ... 24 more ... | "this"'.ts(2769)
Property 'infer' does not exist on type 'Generic<[["t", unknown]], { readonly kind: "foo"; readonly payload: "t"; }, {}, { foo: { bar: "biz"; }; request: bindGenericToScope<GenericAst<[["t", unknown]], { readonly kind: "foo"; readonly payload: "t"; }, {}, {}>, bootstrapAliases<...>>; }>'.ts(2339)
8 Replies
mailliW
mailliWOP2w ago
Don't want anyone to waste their time helping me so I thought I'd say I ended up going with Zod. Looking forward to trying this out again once it's more mature, there's better documentation, and more examples. 🫡
ssalbdivad
ssalbdivad2w ago
@mailliW Sorry I missed this! Been a bit overwhelmed trying to keep up with everything lately. Sorry the docs are very limited. There is this example of defining a generic directly in a scope: https://arktype.io/reference/generics/#scoped My general advice would be if you're just getting into the library, you probably don't need generics. You could just use an intersection (.and or &) to add a set of base properties. I am working on the new docs now though, so do stay tuned for that! I hope it will make things a lot clearer
mailliW
mailliWOP2w ago
Thank you sir! Don't be sorry.. I'm not obligated to your time. I understand you are busy so thanks for making time to respond. I appreciate it I'm not too far along, maybe I'll give it another go this weekend. You have a Venmo or Cashapp or something? I'm only considering using Arktype in side projects for now (I don't have enough sway at my job for such decisions) so I don't have a huge budget, but if you look out for my questions in the future I can send you a little bit for your time.
ssalbdivad
ssalbdivad2w ago
That's very nice of you! If you want you can sponsor the project on GitHub https://github.com/sponsors/arktypeio
GitHub
Sponsor @arktypeio on GitHub Sponsors
ArkType is a type-safe runtime validator that understands TypeScript syntax. Each character you type is statically parsed so you'll know exactly what to expect from editor to runtime.
mailliW
mailliWOP2w ago
Cool, will do! 🙂
ssalbdivad
ssalbdivad2w ago
@mailliW I was trying to figure out if you were the one who recently sponsored the GitHub, then I realized your @ was also your name spelled backwards 😅 Thanks again for your support, it is really helpful 💖 Let me know if you have an X/Bsky account you'd like me to shout out
mailliW
mailliWOP2w ago
No problem at all! I appreciate the offer, but I've been "off the grid" for a few years. I've been considering starting that back up because I'm about to make an attempt a startup, but I haven't yet! 🙂 Thanks for your effort and time on Arktype and on here! 🤗
ssalbdivad
ssalbdivad2w ago
Very cool, good luck and don't hesitate to reach out if you have more questions 😊
Want results from more Discord servers?
Add your server