I am facing problem in schemaTypes of Sanity io All the details are mentioned below Any problem regarding the question U can ask me
userSchema.js
name:'abouts',
title:'Abouts',
type: 'document',
fields:[
{
name:'title',
title:'Title',
type:'string'
},
{
name:'description',
title:'Description',
type:'string'
},
{
name:'imgUrl',
title:'ImgUrl',
type: 'image',
options: {
hotspot: true,
},
},
]
}
schema.js
import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'
import { userSchema } from './userSchema'
export default createSchema({
name: 'default',
types: schemaTypes.concat([userSchema]),
})
Now, schemaTypes is an OBJECT as we can check from "typeof" operator, I dont understand how can we use .concat() with an Object, like .concat() is an array function which can be applied with Array, So how schemaTypes.concat([userSchema]) is working correctly??
Please help me regarding this. Thanks
In JavaScript you will never get 'array'
back from typeof
. typeof
will return 'object'
for any non-primitive other than functions (and the primitive null
).
What I expect you are looking for is the Array.isArray()
method. Logging Array.isArray(schemaTypes)
should return true
, meaning that schemaTypes
is in fact an array and can use the .concat()
method.