SolidJSS
SolidJSโ€ข2y agoโ€ข
14 replies
Pseudotronics

setStore TypeScript Issue

I have a object store that has an interface like this:
export interface config {
  object1?: type1;
  object2?: type2;
  name?: string;
  ...
  id?: number;
}


type1 looks like this:
export interface type1 {
  channel?: number;
  role?: string;
  value?: number;
  present?: boolean;
}


type2 looks like this:
export interface type2 {
  channel?: number;
  role?: string;
  value?: number;
  invert?: boolean;
}


Now I have a components where I pass in the following props struct
 {id: Part<config, keyof config>, setConfig: SetStoreFunction<config>}


Within the component I make calls like:
props.setConfig(props.id, "role", "example")

(where props.id = "object1" or "object2")

These do not create any typescript error.

When I make a call like this:
props.setConfig(props.id, "invert", "example")

(where props.id = "object2")

I get an error like this:
Argument of type '"invert"' is not assignable to parameter of type 'Part<type1| type2, "channel" | "role" | "value">


The code runs fine without error, so I feel like I am not actually using setStore incorrectly.

Why doesn't TypeScript recognize "invert" as valid Part in this situation? Is there any way I can fix this without supressing the TypeScript error?
Was this page helpful?