solid-primitives icon indicating copy to clipboard operation
solid-primitives copied to clipboard

Incompatible signatures for `storage` for `createResource`

Open v1rtl opened this issue 5 months ago • 0 comments

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

v1rtl avatar Aug 02 '25 19:08 v1rtl