solidjs-community / solidjs-community/solid-primitives

Incompatible signatures for `storage` for `createResource`

Open
#806 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
TypeScript
Stars
1.6k
Forks
162
Avg merge
19h 40m
Merged PRs (30d)
8

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

Contributor guide

Open the contributing guide

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 createResource storage option in signal.d.ts around line 324, then compare its expected signature with the storage returned by makePersisted(createSignal()). Use the reproduction in src/resources.ts or the linked StackBlitz to verify the fix; done means the shown createResource call type-checks without the overload error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.