-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Describe the bug
If I define a string field with a list of predefined values, TypeGen generates a union type for that field. However, if I define an array field with a list of predefined values (to get checkboxes in the studio), TypeGen just generates Array<string> as the type of that field.
To Reproduce
Steps to reproduce the behavior:
- Create a project (opting in to TypeScript) or edit an existing one, and make a sanity.config.ts that's something like this:
import {defineConfig, defineType, defineField} from 'sanity'
export default defineConfig({
name: 'default',
title: '<your_project_title>',
projectId: '<your_project_id>',
schema: {
types: [
defineType({
type: 'document',
title: 'Test',
name: 'test',
fields: [
defineField({
name: 'category',
type: 'string',
options: {
list: ['physics', 'chemistry'],
},
}),
defineField({
name: 'element',
type: 'array',
of: [{type: 'string'}],
options: {
list: ['physics', 'chemistry'],
},
}),
],
}),
],
},
})
npx sanity schema extract && npx sanity typegen generateand observe the generated types (e.g. sanity.types.ts)
Expected behavior
export type Test = {
_id: string
_type: 'test'
_createdAt: string
_updatedAt: string
_rev: string
category?: 'physics' | 'chemistry'
element?: Array<'physics' | 'chemistry'>
}
Actual behavior
export type Test = {
_id: string
_type: 'test'
_createdAt: string
_updatedAt: string
_rev: string
category?: 'physics' | 'chemistry'
element?: Array<string>
}
Which versions of Sanity are you using?
@sanity/cli (global) 3.41.1 (up to date)
@sanity/eslint-config-studio 4.0.0 (up to date)
@sanity/vision 3.41.1 (up to date)
sanity 3.41.1 (up to date)
What operating system are you using?
GNU/Linux (Ubuntu 22.04.4 LTS)
Which versions of Node.js / npm are you running?
npm -v && node -v:
10.2.4
v20.11.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels