sanity-io / code-input

Code input and schema for Sanity Studio
MIT License
20 stars 3 forks source link

Type Error with codeInput() in sanity.config.ts #105

Open leeuwd opened 3 weeks ago

leeuwd commented 3 weeks ago

Describe the bug

I'm encountering a type error when using the codeInput() function in my Sanity configuration file (sanity.config.ts).

import { defineConfig } from 'sanity'
import { schemas } from './schemas'
import { codeInput } from '@sanity/code-input'

export default defineConfig({
  name: 'default',
  title: 'Something',
  projectId: '123',
  dataset: 'production',
  schema: {
    types: schemas,
  },
  plugins: [codeInput()],
})

Error

Types of property schema are incompatible.
Type 'import("[redacted]/node_modules/sanity/lib/index", { with: { "resolution-mode": "import" } }).SchemaPluginOptions | undefined' is not assignable to type 'import("[redacted]/node_modules/sanity/lib/index").SchemaPluginOptions | undefined'.
Type 'import("[redacted]/node_modules/sanity/lib/index", { with: { "resolution-mode": "import" } }).SchemaPluginOptions' is not assignable to type 'import("[redacted]/node_modules/sanity/lib/index").SchemaPluginOptions'.
Types of property types are incompatible.
Type 'import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).SchemaTypeDefinition[] | import("[redacted]/node_modules/sanity/lib/index", { with: { "resolution-mode": "import" } }).ComposableOption<import("[redacted]/node_modules/supe...' is not assignable to type 'import("[redacted]/node_modules/@sanity/types/lib/index").SchemaTypeDefinition[] | import("[redacted]/node_modules/sanity/lib/index").ComposableOption<import("[redacted]/node_modules/@sanity/types/lib/index").SchemaTypeDefinition[], Omit<...>> | un...'.
Type SchemaTypeDefinition[] is not assignable to type
SchemaTypeDefinition[] | ComposableOption<SchemaTypeDefinition[], Omit<ConfigContext, 'schema' | 'i18n' | 'currentUser' | 'getClient' | 'client'>> | undefined
Type 'import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).SchemaTypeDefinition[]' is not assignable to type 'import("[redacted]/node_modules/@sanity/types/lib/index").SchemaTypeDefinition[]'.
Type 'import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).SchemaTypeDefinition' is not assignable to type 'import("[redacted]/node_modules/@sanity/types/lib/index").SchemaTypeDefinition'.
Type StringDefinition is not assignable to type SchemaTypeDefinition
Type StringDefinition is not assignable to type
StringDefinition | TypeAliasDefinition<string, "string" | "number" | "boolean" | "object" | "document" | "array" | "block" | "date" | "datetime" | "file" | "geopoint" | "image" | ... 5 more ... | "email">
Type 'import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).StringDefinition' is not assignable to type 'import("[redacted]/node_modules/@sanity/types/lib/index").StringDefinition'.
Types of property validation are incompatible.
Type 'import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).ValidationBuilder<import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).StringRule, string> | undefined' is not assignable to type 'import("[redacted]/node_modules/@sanity/types/lib/index").ValidationBuilder<import("[redacted]/node_modules/@sanity/types/lib/index").StringRule, string> | undefined'.
Type 'import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).ValidationBuilder<import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).StringRule, string>' is not assignable to type 'import("[redacted]/node_modules/@sanity/types/lib/index").ValidationBuilder<import("[redacted]/node_modules/@sanity/types/lib/index").StringRule, string>'.
Types of parameters rule and rule are incompatible.
Type 'import("[redacted]/node_modules/@sanity/types/lib/index").StringRule' is not assignable to type 'import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).StringRule'.
Types of property regex are incompatible.
Type '{ (pattern: RegExp, name: string, options: { name?: string | undefined; invert?: boolean | undefined; }): import("[redacted]/node_modules/@sanity/types/lib/index").StringRule; (pattern: RegExp, options: { ...; }): import("[redacted]/node_modules/@sanity/types/lib/index")...' is not assignable to type '{ (pattern: RegExp, name: string, options: { name?: string | undefined; invert?: boolean | undefined; }): import("[redacted]/node_modules/@sanity/types/lib/index", { with: { "resolution-mode": "import" } }).StringRule; (pattern: RegExp, options: { ...; }): import("[redacted]/node_modules/superco...'.
Target signature provides too few arguments. Expected 3 or more, but got 2

Which versions of Sanity are you using?

@sanity/cli (global)          3.46.1 (up to date)
@sanity/code-input             4.1.4 (up to date)
@sanity/eslint-config-studio   4.0.0 (up to date)
@sanity/icons                  3.2.0 (up to date)
@sanity/ui                     2.3.6 (up to date)
@sanity/vision                3.46.1 (up to date)
sanity                        3.46.1 (up to date)

What operating system are you using?

macOS

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

10.2.4
v20.11.1

Additional context

Turborepo monorepo.

leeuwd commented 3 weeks ago

In addition, the import:

TS1479: The current file is a CommonJS module whose imports will produce require calls; however, the referenced file is an ECMAScript module and cannot be imported with require. Consider writing a dynamic import(@sanity/code-input)' call instead.
To convert this file to an ECMAScript module, change its file extension to .mts, or add the field `type: module` to