A
arktype3w ago
Micha

How to create an array of type.instanceOf?

This doesn't work:
const documentReference = type.instanceOf(DocumentReference);

scope({
user: {
accounts: "documentReference[]",
}
}
const documentReference = type.instanceOf(DocumentReference);

scope({
user: {
accounts: "documentReference[]",
}
}
const documentReference = type.instanceOf(DocumentReference);

scope({
user: {
accounts: type.instanceOf(DocumentReference)[],
}
}
const documentReference = type.instanceOf(DocumentReference);

scope({
user: {
accounts: type.instanceOf(DocumentReference)[],
}
}
I only get it working without an array:
const documentReference = type.instanceOf(DocumentReference);

scope({
account: {
user: type.instanceOf(DocumentReference),
}
}
const documentReference = type.instanceOf(DocumentReference);

scope({
account: {
user: type.instanceOf(DocumentReference),
}
}
3 Replies
Micha
MichaOP3w ago
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
ssalbdivad
ssalbdivad3w ago
This isn't safe because there's no way to know at runtime what the array is supposed to include. type.instanceOf creates a Type like any other, meaning you can just chain the standard .array() method off it like type.instanceOf(DocumentReference).array()
Micha
MichaOP3w ago
Great, thanks a lot ❤️

Did you find this page helpful?