mailliW
mailliW
Aarktype
Created by mailliW on 11/9/2024 in #questions
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)
11 replies