Skip to content
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

schema extraction incorrectly marks hotspot & crop values as optional #8060

Open
RJWadley opened this issue Dec 13, 2024 · 0 comments
Open

Comments

@RJWadley
Copy link

Describe the bug

Sanity studio never sets a hotspot or crop value with only partial properties, even if it's a draft document. The schema extractor marks these as optional, which means any generated types will be too loose. This makes working with these values in typescript more complex.
Here's an example from sanity.imageHotspot. Note the added "optional": true that should not be present.

"x": {
  "type": "objectAttribute",
  "value": {
    "type": "number"
  },
  "optional": true
},

And, for the sake of completeness, this is the type that comes out:

export type SanityImageHotspot = {
	_type: "sanity.imageHotspot"
	x?: number
	y?: number
	height?: number
	width?: number
}

To Reproduce

Steps to reproduce the behavior:

  1. create a schema that uses an "image" type
  2. run sanity schema extract to extract the schema
  3. locate either "sanity.imageHotspot" or "sanity.imageCrop"
  4. note that "optional": true is specified on all its attributes

Expected behavior

This is what the correct output for the above example would be:

"x": {
  "type": "objectAttribute",
  "value": {
    "type": "number"
  },
},

and this is what the corresponding correct type would be:

export type SanityImageHotspot = {
	_type: "sanity.imageHotspot"
	x: number
	y: number
	height: number
	width: number
}

Which versions of Sanity are you using?

@sanity/cli (global)        3.67.1 (up to date)
@sanity/assist               3.0.8 (up to date)
@sanity/icons                3.5.2 (up to date)
@sanity/image-url            1.1.0 (up to date)
@sanity/preview-url-secret   2.0.5 (up to date)
@sanity/vision              3.67.1 (up to date)
sanity                      3.67.1 (up to date)

What operating system are you using?
MacOS Sequoia 15.1.1 (24B91)

Which versions of Node.js / npm are you running?

10.9.0
v22.11.0

Additional context

No additional context

Security issue?

Not a security issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant