solid icon indicating copy to clipboard operation
solid copied to clipboard

Wrong typescript type on createStore when using generics

Open hymbz opened this issue 6 months ago • 0 comments

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

hymbz avatar Jul 06 '25 13:07 hymbz