cross posting from #typescript

noob question! how would i express this type using arktype syntax?
type MyType = Record<string, unknown>[]
type MyType = Record<string, unknown>[]
i tried:
type(type.Record("string", type.unknown), "[]")
type(type.Record("string", type.unknown), "[]")
but it doesn't work on v2.0.0-rc.30.
7 Replies
ssalbdivad
ssalbdivad3w ago
I would just chain .array() instead of using the args syntax:
type.Record("string", type.unknown).array()
type.Record("string", type.unknown).array()
What you wrote should work but it seems like a TypeScript bug It does work if you split it up though so some TS issue related to the inner inference:
const dict = type.Record("string", type.unknown)

const t = type(dict, "[]")
const dict = type.Record("string", type.unknown)

const t = type(dict, "[]")
Or this if you prefer I suppose:
const t = type({ "[string]": "unknown" }, "[]")
const t = type({ "[string]": "unknown" }, "[]")
ahrjarrett
ahrjarrettOP3w ago
thanks for the quick response! hmm, i don't know if splitting it up is an option. let me try .array() i'm doing this programmatically, so i need to make sure i'm able to detect when to use which syntax, in which context will .array() work in all cases?
ssalbdivad
ssalbdivad3w ago
You're generating ArkType definitions?
ahrjarrett
ahrjarrettOP3w ago
yeah
ssalbdivad
ssalbdivad3w ago
Yeah .array() should be the most reliable nothing can really go wrong
ahrjarrett
ahrjarrettOP3w ago
cool, thank youuu you're the best
ssalbdivad
ssalbdivad3w ago
As long as you avoid nested type calls or nested tuple expressions you should be pretty safe in general though Stuff like your original definition generally works but TS has weird rules around inference that can sometimes get in the way. As long as you don't have anything like that or nested tuple expressions for a similar reason all roads should lead to Rome or whatever haha

Did you find this page helpful?