Skip to content

Commit

Permalink
Merge b7cd119 into eb253cb
Browse files Browse the repository at this point in the history
  • Loading branch information
otonashixav committed Feb 13, 2023
2 parents eb253cb + b7cd119 commit 091b7a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-dots-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

Fixed test case for setStore 7 parameter overload by fixing KeyOf giving number for KeyOf<never>
6 changes: 3 additions & 3 deletions packages/solid/store/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ export type Part<T, K extends KeyOf<T> = KeyOf<T>> =
type W<T> = Exclude<T, NotWrappable>;

// specially handle keyof to avoid errors with arrays and any
type KeyOf<T> = number extends keyof T // have to check this otherwise ts won't allow KeyOf<T> to index T
type KeyOf<T> = [T] extends [never]
? never // handle never first
: number extends keyof T // have to check this otherwise ts won't allow KeyOf<T> to index T
? 0 extends 1 & T // if it's any just return keyof T
? keyof T
: [T] extends [readonly unknown[]]
? number // it's an array or tuple; exclude the non-number properties
: [T] extends [never]
? never // keyof never is PropertyKey which number extends; return never
: keyof T // it's something which contains an index signature for strings or numbers
: keyof T;

Expand Down
2 changes: 1 addition & 1 deletion packages/solid/store/test/store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ describe("Nested Classes", () => {
// @ts-expect-error m is readonly
setK5("i", "j", "k", "l", "m", 6);
const [, setK6] = createStore({} as { i: { j: { k: { l: { m: { readonly n: number } } } } } });
// TODO @ts-expect-error n is readonly, but has unreadable error due to method overloading
// @ts-expect-error n is readonly, but has unreadable error due to method overloading
setK6("i", "j", "k", "l", "m", "n", 7);
const [, setK7] = createStore(
{} as { i: { j: { k: { l: { m: { n: { readonly o: number } } } } } } }
Expand Down

0 comments on commit 091b7a0

Please sign in to comment.