solidjs / solid

A declarative, efficient, and flexible JavaScript library for building user interfaces.
https://solidjs.com
MIT License
31.64k stars 887 forks source link

TypeScript Error: setStore types inferred incorrectly #2197

Closed pseudotronics closed 5 days ago

pseudotronics commented 5 days ago

Describe the bug

I have a store object that contains two separate object types as properties. TypeScript only considers the overlapping properties of each type as valid Parts.

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

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

export interface config {
  item1?: type1;
  item2?: type2;
  item3?: type1;
  item4?: type2;
  name?: string;
  id?: number;
}

TypeScript is throwing a "Argument of type '"invert"' is not assignable to parameter of type 'Part<type1 | type2, "channel" | "role" | "value">'." error for what appears to be valid code.

The provided example runs without issue.

Your Example Website or App

https://stackblitz.com/edit/solidjs-templates-xgprfg?file=src%2FApp.tsx

Steps to Reproduce the Bug or Issue

  1. open the example
  2. review typescript errors

Expected behavior

From what I understand the Part type should be:

Part<type1 | type2, "channel" | "role" | "value" | "present" | "invert">

but instead it is being interpreted as:

Part<type1 | type2, "channel" | "role" | "value">

Is there some way to define the Part more narrowly at the component level?

Screenshots or Videos

No response

Platform

Additional context

No response