
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe error is happening because parent.projectType is undefined when your conditional hidden functions run, but you're calling .includes() on it without checking if it exists first.
Fix: Add optional chaining to safely handle undefined values:
hidden: ({parent}: {parent: {projectType?: string[]}}) =>
!parent.projectType?.includes('building'),Apply this pattern to all three conditional fields (numFloors, numUnits, and numOfHouses).
The ?. operator will return undefined if projectType is undefined, and since !undefined is true, the fields will be hidden by default when no project type is selected - which is exactly what you want.
This typically breaks when creating new documents or when the projectType field hasn't been set yet. The optional chaining prevents the error and provides sensible default behavior.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store