solidjs-community/solid-primitives

Incompatible signatures for `storage` for `createResource`

Ouverte

#806 ouverte le 2 août 2025

 (1 commentaire) (2 réactions) (0 personne assignée)TypeScript (153 forks)auto 404
help wanted

Métriques du dépôt

Stars
 (1 541 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

Describe the bug

No overload matches this call.
  Overload 1 of 4, '(fetcher: ResourceFetcher<true, StakeRecord[], unknown>, options: InitializedResourceOptions<StakeRecord[], true>): InitializedResourceReturn<...>', gave the following error.
    Type '[get: Accessor<StakeRecord | undefined>, set: Setter<StakeRecord | undefined>, init: string | Promise<string> | null]' is not assignable to type '(init: StakeRecord[] | undefined) => [Accessor<StakeRecord[] | undefined>, Setter<StakeRecord[] | undefined>]'.
      Type '[get: Accessor<StakeRecord[] | undefined>, set: Setter<StakeRecord | undefined>, init: string | Promise<string> | null]' provides no match for the signature '(init: StakeRecord[] | undefined): [Accessor<StakeRecord[] | undefined>, Setter<StakeRecord[] | undefined>]'.
  Overload 2 of 4, '(fetcher: ResourceFetcher<true, StakeRecord[], unknown>, options?: ResourceOptions<StakeRecord[], true> | undefined): ResourceReturn<...>', gave the following error.
    Type '[get: Accessor<StakeRecord | undefined>, set: Setter<StakeRecord | undefined>, init: string | Promise<string> | null]' is not assignable to type '(init: StakeRecord[] | undefined) => [Accessor<StakeRecord[] | undefined>, Setter<StakeRecord[] | undefined>]'.
      Type '[get: Accessor<StakeRecord[] | undefined>, set: Setter<StakeRecord | undefined>, init: string | Promise<string> | null]' provides no match for the signature '(init: StakeRecord[] | undefined): [Accessor<StakeRecord[] | undefined>, Setter<StakeRecord[] | undefined>]'.
  Overload 3 of 4, '(source: ResourceSource<Promise<StakeRecord[]>>, fetcher: ResourceFetcher<Promise<StakeRecord[]>, unknown, unknown>, options?: ResourceOptions<...> | undefined): ResourceReturn<...>', gave the following error.
    Object literal may only specify known properties, and 'storage' does not exist in type 'ResourceFetcher<Promise<StakeRecord[]>, unknown, unknown>'.ts(2769)
signal.d.ts(324, 3): The expected type comes from property 'storage' which is declared here on type 'InitializedResourceOptions<StakeRecord[], true>'

Reproduction:

import { makePersisted } from '@solid-primitives/storage'
import { createResource, createSignal, ResourceFetcher } from 'solid-js'

type StakeRecord = number // or whatever other type you want

const storage = <T>() => makePersisted(createSignal<T>())

const fetchEffectiveStakes = async (): Promise<StakeRecord[]> => {
  const response = await fetch(
   '/stakes',
  )
  return await response.json() as StakeRecord[]
}

export const effectiveStakes = () =>
  createResource(fetchEffectiveStakes, { storage: storage<StakeRecord[]>() }) // type error here

Minimal Reproduction Link

https://stackblitz.com/edit/github-jrdxdxx5?file=src%2Fresources.ts

Guide contributeur