A
arktype2mo ago
Sorato

string.date.parse does not work on cyclic objects

Hello, i did not find anything related to this, but if i have a cyclic type like this:
export const types = scope({
User: {
"id": "number",
"supervisor": "User"
"createdAt": "string.date.parse"
}
})
export const types = scope({
User: {
"id": "number",
"supervisor": "User"
"createdAt": "string.date.parse"
}
})
if i try to parse it like:
const user = types.User(data)
const user = types.User(data)
then only the createdAt of the user itself gets a Date, but user.supervisor.createdAt stays a string. how can i fix this? thanks a lot!
5 Replies
ssalbdivad
ssalbdivad2mo ago
Hmm if that's occuring it sounds like it could be a bug. Could you post a full repro, potentially using the playground? https://arktype.io/playground I tried the following but it seemed to have as expected:
import { scope } from "arktype"

export const types = scope({
User: {
id: "number",
"supervisor?": "User",
createdAt: "string.date.parse"
}
}).export()

const data = types.User({
id: 5,
supervisor: {
id: 7,
createdAt: "0"
},
createdAt: "1"
})

console.log(data)
import { scope } from "arktype"

export const types = scope({
User: {
id: "number",
"supervisor?": "User",
createdAt: "string.date.parse"
}
}).export()

const data = types.User({
id: 5,
supervisor: {
id: 7,
createdAt: "0"
},
createdAt: "1"
})

console.log(data)
Sorato
SoratoOP2mo ago
so my example was bad, sorry for that.
ssalbdivad
ssalbdivad4w ago
Yeah this is definitely wrong, thanks for the follow up. Can you log a github issue with this repro so we can track fixing it?
Sorato
SoratoOP4w ago
i did, hope thats enough context: https://github.com/arktypeio/arktype/issues/1486
GitHub
string.date.parse does not work on cyclic objects · Issue #1486 ·...
Report a bug In the example below, only the "main" object`s createdAt gets parsed correctly, the main.supervisor.createdAt stays a string. that has something to do with this: "superv...

Did you find this page helpful?