-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type error: Object literal may only specify known properties, and 'preview' does not exist in type 'DocumentComponents'. #6542
Comments
Hey @marcinincreo. Please can you share your full |
Hi @juice49 defineType code: import { defineField, defineType } from "sanity";
import LayoutItem from "sanity/components/LayoutItem";
import { StackCompactIcon } from "@sanity/icons";
export default defineType({
title: "Accordion",
name: "accordion",
type: "document",
icon: StackCompactIcon,
fields: [
defineField({
title: "Tittel",
name: "title",
type: "string",
validation: (Rule) => Rule.required(),
}),
],
components: {
preview: LayoutItem,
},
}); Custom component code: import { Flex } from "@sanity/ui";
const LayoutItem = (props) => {
return <Flex>{props.renderDefault(props)}</Flex>;
};
export default LayoutItem; |
Thank you! Do you see the error when you run a type check directly ( |
tsc
accordion.ts:26:5 - error TS2353: Object literal may only specify known properties, and 'preview' does not exist in type 'DocumentComponents'.
26 preview: LayoutItem,
~~~~~~~
node_modules/.pnpm/sanity@3.40.0_@types+node@20.12.10_@types+react@18.3.1_react-dom@18.3.1_react@18.3.1_styled-components@6.1.9/node_modules/sanity/lib/_singletons.d.ts:8540:5
8540 components?: DocumentComponents
~~~~~~~~~~
The expected type comes from property 'components' which is declared here on type '{ type: "document"; name: "accordion"; } & Omit<DocumentDefinition, "preview"> & { preview?: PreviewConfig<{ title: string; items: string; }, Record<"title" | "items", any>>; }' |
Hey 😄 We also receive the same issue, via typescript language server and when attempting to build in strict mode.
We have ts-ignored the type issue for now as we didn't see any breaking changes in the latest changelogs. |
As an FYI, this issue also affects the official plugin |
Hi I'm now investigating this issue. I think it has something to do with how typescript handles declaration merging. To avoid cyclical dependencies in our code, we leverage declaration merging here… sanity/packages/sanity/src/core/form/types/definitionExtensions.ts Lines 306 to 307 in bec0ff3
where the sanity/packages/sanity/src/core/form/types/definitionExtensions.ts Lines 448 to 455 in bec0ff3
I'm not sure why this is occuring. Might be due to a mismatch in versions? Can you provide your package.json and lockfiles if possible? Alternatively if you could put up a reproduction in a repo somewhere, that would definitely help us get to the bottom of this. As cliche as this sounds, I would recommend ensuring that all versions of sanity in your package.jsons are the same and then nuking your lockfiles and reinstalling. |
Followed up with the advice but outcome remains the same. To make sure this is not related to the project I worked on I created a new sanity installation with package.json: {
"name": "sanity-test",
"private": true,
"version": "1.0.0",
"main": "package.json",
"license": "UNLICENSED",
"scripts": {
"dev": "sanity dev",
"start": "sanity start",
"build": "sanity build",
"deploy": "sanity deploy",
"deploy-graphql": "sanity graphql deploy"
},
"keywords": [
"sanity"
],
"dependencies": {
"@sanity/vision": "^3.42.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sanity": "^3.42.1",
"styled-components": "^6.1.8"
},
"devDependencies": {
"@sanity/eslint-config-studio": "^4.0.0",
"@types/react": "^18.0.25",
"eslint": "^8.6.0",
"prettier": "^3.0.2",
"typescript": "^5.1.6"
},
"prettier": {
"semi": false,
"printWidth": 100,
"bracketSpacing": false,
"singleQuote": true
}
} |
This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread. |
Type error: Object literal may only specify known properties, and 'preview' does not exist in type 'DocumentComponents'. occurs when using
custom preview component
indefineType
method:components: { preview: ExamplePreviewComponent, },
Which versions of Sanity are you using?
What operating system are you using?
Which versions of Node.js / npm are you running?
The text was updated successfully, but these errors were encountered: