Skip to content

Wrong typescript type on createStore when using generics #2510

@hymbz

Description

@hymbz

Describe the bug

The follow code generates the type error:

import { createStore } from "solid-js/store";

type defaultStore = {
  a: boolean;
};

const aa = <T extends Record<string, boolean>>(init: T) => {
  const [store, setStore] = createStore<T & defaultStore>({
    a: false,
    ...init,
  });

  setStore("a", true);  // Argument of type 'string' is not assignable to parameter of type 'Part<Exclude<T & defaultStore, NotWrappable>, MutableKeyOf<Exclude<T & defaultStore, NotWrappable>>>'.
  setStore({ a: true });  // Object literal may only specify known properties, and 'a' does not exist in type 'never'.
};

Your Example Website or App

https://playground.solidjs.com/anonymous/43a5de23-fdb1-40a7-983e-5a5ed2b1c2c9

Steps to Reproduce the Bug or Issue

enter the code

Expected behavior

no errors

Screenshots or Videos

No response

Platform

solid 1.9.7

Additional context

No response

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