Skip to content

makePersisted() cannot correctly infer types under Typescript 7 #1000

Description

@Atulin

Describe the bug

const [thing, setThing] = makePersisted(createSignal("hello"), {
    name: "thing",
    storage: localStorage,
});
> tsc --noEmit

src/App.tsx(8,43): error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'Signal<string>' is not assignable to parameter of type 'Signal<unknown> | [unknown, SetStoreFunction<unknown>]'.
      Type '[get: Accessor<string>, set: Setter<string>]' is not assignable to type 'Signal<unknown>'.
        Type at position 1 in source is not compatible with type at position 1 in target.
          Type 'Setter<string>' is not assignable to type 'Setter<unknown>'.
            Target signature provides too few arguments. Expected 1 or more, but got 0.

Currently, the only way to fix it seems to be to provide full, explicit types:

const [thing, setThing] = makePersisted<string, Signal<string>>(createSignal("hello"), {
    name: "thing",
    storage: localStorage,
});

Minimal Reproduction Link

https://stackblitz.com/edit/github-ojctyhmm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions