nuxt-modules / nuxt-modules/sanity

Wrong type when using image-url like in the example?

Open
#920 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
TypeScript
Stars
265
Forks
43
Avg merge
11h
Merged PRs (30d)
18

Description

Following example from here:

import imageUrlBuilder from '@sanity/image-url'

export default defineNuxtPlugin(() => {
  const builder = imageUrlBuilder(useSanity().config) // <-- here is the problem
  function urlFor(source) {
    return builder.image(source).auto('format')
  }
  return {
    provide: { urlFor }
  }
})

Doesn't work for me as the type seems wrong:

Argument of type 'SanityConfiguration' is not assignable to parameter of type 'SanityClientLike | SanityProjectDetails | SanityModernClientLike | undefined'.
  Type 'SanityConfiguration' is not assignable to type 'SanityProjectDetails'.
    Types of property 'dataset' are incompatible.
      Type 'string | undefined' is not assignable to type 'string'.
        Type 'undefined' is not assignable to type 'string'.ts(2345)

Should this work?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked documentation example and the useSanity().config call passed to imageUrlBuilder. Check the relevant TypeScript definitions and reproduce the reported SanityConfiguration error; done when the documented example type-checks with the intended configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.