Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug Report] Validation error: Property 'uri' does not exist on type 'StringRule' #8422

Open
rylanharper opened this issue Jan 27, 2025 · 0 comments

Comments

@rylanharper
Copy link

Describe the bug

Using uri on the validation property rule will throw a types error saying it does not exist, when it does.

To Reproduce

Simply create an validation property in any TS file using uri:

defineField({
  name: 'url',
  title: 'URL',
  description: 'Enter an external URL path',
  type: 'string',
  validation: (Rule) =>
    Rule.required().uri({
      scheme: ['http', 'https', 'mailto', 'tel']
    })
})

This will throw a TS error: Property 'uri' does not exist on type 'StringRule'.ts(2339)

Expected behavior

uri is still valid, along with its corresponding message flag. It should be added to the StringRule types. The current StringRule types are here:

export declare interface StringRule extends RuleDef<StringRule, string> {
  min: (minNumber: number | FieldReference) => StringRule
  max: (maxNumber: number | FieldReference) => StringRule
  length: (exactLength: number | FieldReference) => StringRule
  uppercase: () => StringRule
  lowercase: () => StringRule
  regex(
    pattern: RegExp,
    name: string,
    options: {
      name?: string
      invert?: boolean
    },
  ): StringRule
  regex(
    pattern: RegExp,
    options: {
      name?: string
      invert?: boolean
    },
  ): StringRule
  regex(pattern: RegExp, name: string): StringRule
  regex(pattern: RegExp): StringRule
  email(): StringRule
}

Which versions of Sanity are you using?

sanity 3.71.2 (up to date)

What operating system are you using?

pnpm v9.15.4
node v22.12.0

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

No branches or pull requests

1 participant