Micha
Micha
Aarktype
Created by Micha on 2/5/2025 in #questions
Why is the generic expecting 3 options, although there is only one generic prop?
Got it - subscribed to the issue - thaaanks 🙂
5 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
scope() how to bypass circular reference error?
I think I go for now with this one:
const types = type
.scope({
queryValue: "namedDocument<Record<string, unknown>>",
queryValueObject: {
"[string]": "queryValue",
},

"namedDocument<metadata extends Record<string, unknown>>": {
"data?": "metadata",
},
})
.export();
const types = type
.scope({
queryValue: "namedDocument<Record<string, unknown>>",
queryValueObject: {
"[string]": "queryValue",
},

"namedDocument<metadata extends Record<string, unknown>>": {
"data?": "metadata",
},
})
.export();
14 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
scope() how to bypass circular reference error?
Sound like you should consider writing your own compiler to get beyond such problems 😛
14 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
scope() how to bypass circular reference error?
Do you think this is solvable, and should I create a GitHub issue, or is it a general limitation?
14 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
scope() how to bypass circular reference error?
This is the working equivalent in typescript:
type QueryValue = NamedDocument
type QueryValueObject = {
[key: string]: QueryValue
}

type NamedDocument<metadata extends QueryValueObject = Record<string, never>> = {
data?: metadata
}
type QueryValue = NamedDocument
type QueryValueObject = {
[key: string]: QueryValue
}

type NamedDocument<metadata extends QueryValueObject = Record<string, never>> = {
data?: metadata
}
14 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
How to integrate generics with extend that need to access a type in scope?
I have to say I'm quite impressed with how far I have already come without a painful workaround (I say only cyclic references + zod... 😉 ). You did here definitely an outstanding job 👍
15 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
How to integrate generics with extend that need to access a type in scope?
awesome - that is what I need. My goal was to group the types logically to keep it a bit tidy 🙂
15 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
How to integrate generics with extend that need to access a type in scope?
The way you phrase it, sounds like it's a limitation?
15 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
How to integrate generics with extend that need to access a type in scope?
I've updated it, but I'm still getting an error that metadata is unresolvable Type '"metadata"' is not assignable to type '"'metadata' is unresolvable "'.ts(2322):
scope({
queryValue: [
"null | string | number | bigint | boolean | queryValueObject | queryValue[]",
uint8Array,
dateStub,
timeStub,
module,
],
queryValueObject: {
"[string]": "queryValue",
},
namedDocument: {
"read<metadata extends queryValueObject>": {
coll: module,
name: "string",
ts: timeStub,
"data?": "metadata",
}
},
}).export();
scope({
queryValue: [
"null | string | number | bigint | boolean | queryValueObject | queryValue[]",
uint8Array,
dateStub,
timeStub,
module,
],
queryValueObject: {
"[string]": "queryValue",
},
namedDocument: {
"read<metadata extends queryValueObject>": {
coll: module,
name: "string",
ts: timeStub,
"data?": "metadata",
}
},
}).export();
If I'm renaming "metadata" to "t" the error changes to Type '"t"' is not assignable to type '"true"'.ts(2322)
"read<t extends queryValueObject>": {
coll: module,
name: "string",
ts: timeStub,
"data?": "t",
}
"read<t extends queryValueObject>": {
coll: module,
name: "string",
ts: timeStub,
"data?": "t",
}
15 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
How to integrate generics with extend that need to access a type in scope?
oh, somehow I missed this part in the docs, although I have read over this today probably already 10 times 😬
15 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
How to create the Typescript type from a generic?
All right - thanks a lot for your help! 🙂
7 replies
Aarktype
Created by Micha on 2/4/2025 in #questions
How to create the Typescript type from a generic?
ah ok, good to know, so this seems working:
const test = namedDocument(func).infer;
const test4: typeof test
const test = namedDocument(func).infer;
const test4: typeof test
Is it also possible to write that shorter? Something like this? (In this case he seems not liking the function call)
const test3: typeof namedDocument(func).infer = {
body: "string",
role: "string"
}
const test3: typeof namedDocument(func).infer = {
body: "string",
role: "string"
}
7 replies
Aarktype
Created by Micha on 2/3/2025 in #questions
What is the arktype 2 syntax for inferring classes with a private constructor?
Awesome - you're a live saver! ❤️
6 replies
Aarktype
Created by Micha on 2/3/2025 in #questions
What is the arktype 2 syntax for inferring classes with a private constructor?
Like this?
export const document_update = type({
"ttl?": TimeStub as type.cast<TimeStub>,
});
export const document_update = type({
"ttl?": TimeStub as type.cast<TimeStub>,
});
6 replies
Aarktype
Created by Micha on 2/3/2025 in #questions
How to create an array of type.instanceOf?
Great, thanks a lot ❤️
4 replies
Aarktype
Created by Micha on 2/3/2025 in #questions
What is the arktype 2 syntax for inferring classes with a private constructor?
Seems I'm getting a bit closer:
const document = type({
"ttl?": type.instanceOf(TimeStub) as type.infer<TimeStub>,
});
const document = type({
"ttl?": type.instanceOf(TimeStub) as type.infer<TimeStub>,
});
But this throws a conversion error:
Conversion of type 'Type<TimeStub, {}>' to type '{ isoString: never; toDate: {}; toString: {}; }' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type 'Type<TimeStub, {}>' is missing the following properties from type '{ isoString: never; toDate: {}; toString: {}; }': isoString, toDatets(2352)
Conversion of type 'Type<TimeStub, {}>' to type '{ isoString: never; toDate: {}; toString: {}; }' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type 'Type<TimeStub, {}>' is missing the following properties from type '{ isoString: never; toDate: {}; toString: {}; }': isoString, toDatets(2352)
If I cast it to unknown
export const document_update = type({
"ttl?": type.instanceOf(TimeStub) as unknown as type.infer<TimeStub>,
});
export const document_update = type({
"ttl?": type.instanceOf(TimeStub) as unknown as type.infer<TimeStub>,
});
then I get again back to the initial error:
Argument of type 'typeof TimeStub' is not assignable to parameter of type 'Constructor<TimeStub>'.
Cannot assign a 'private' constructor type to a 'public' constructor type.ts(2345)
Argument of type 'typeof TimeStub' is not assignable to parameter of type 'Constructor<TimeStub>'.
Cannot assign a 'private' constructor type to a 'public' constructor type.ts(2345)
6 replies
Aarktype
Created by Micha on 2/3/2025 in #questions
How to create an array of type.instanceOf?
This is working 🎉:
type.instanceOf(Array<DocumentReference>)
type.instanceOf(Array<DocumentReference>)
Maybe it's worth adding this example also to the docs? https://arktype.io/docs/objects#instanceof @ArkDavid
4 replies