Skip to content

Incompatible signatures for storage for createResource #806

Description

@v1rtl

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions