Skip to content

Commit

Permalink
Resolve issue #2026
Browse files Browse the repository at this point in the history
  • Loading branch information
dfahlander committed Jul 1, 2024
1 parent 795f60c commit 4361ca6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/public/types/keypaths.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
export type KeyPaths<T> = {
[P in keyof T]:
P extends string
? T[P] extends Array<infer K>
? K extends object // only drill into the array element if it's an object
? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<K>}`
: P | `${P}.${number}`
: T[P] extends (...args: any[]) => any // Method
? never
: T[P] extends object
? P | `${P}.${KeyPaths<T[P]>}`
: P
: never;
[P in keyof T]: P extends string
? T[P] extends Array<infer K>
? K extends any[] // Array of arrays (issue #2026)
? P | `${P}.${number}` | `${P}.${number}.${number}`
: K extends object // only drill into the array element if it's an object
? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<K>}`
: P | `${P}.${number}`
: T[P] extends (...args: any[]) => any // Method
? never
: T[P] extends object
? P | `${P}.${KeyPaths<T[P]>}`
: P
: never;
}[keyof T];

export type KeyPathValue<T, PATH> = PATH extends `${infer R}.${infer S}`
Expand Down
7 changes: 6 additions & 1 deletion test/typings-test/test-typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,17 @@ import './test-updatespec';
isGoodFriend: boolean;
address: {
city: string;
}
},
matrix: number[][]; // Trigger issue #2026
}

let db = new Dexie('dbname') as Dexie & {friends: Table<Friend, number>};

db.friends.where({name: 'Kalle'}).modify({name: replacePrefix('K', 'C')});

// Issue #2026
db.friends.update(1, {"address.city": "New York"});
db.friends.update(2, {matrix: [[1,2]]});
}


Expand Down

0 comments on commit 4361ca6

Please sign in to comment.