mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 19:46:36 +00:00
Adjust DataTable types.
- Make key in `cell` slot prop less strict to prevent type errors in markup. - Resolve property path names up to one level deep for header keys.
This commit is contained in:
parent
aa45b63ff1
commit
2b6c7b0ade
7 changed files with 73 additions and 21 deletions
5
types/DataTable/DataTable.svelte.d.ts
vendored
5
types/DataTable/DataTable.svelte.d.ts
vendored
|
@ -1,7 +1,8 @@
|
|||
import type { SvelteComponentTyped } from "svelte";
|
||||
import type { SvelteHTMLElements } from "svelte/elements";
|
||||
|
||||
export type DataTableKey<Row = DataTableRow> = Exclude<keyof Row, "id">;
|
||||
export type DataTableKey<Row = DataTableRow> =
|
||||
import("./DataTableTypes.d.ts").PropertyPath<Row>;
|
||||
|
||||
export type DataTableValue = any;
|
||||
|
||||
|
@ -37,7 +38,7 @@ export interface DataTableRow {
|
|||
export type DataTableRowId = any;
|
||||
|
||||
export interface DataTableCell<Row = DataTableRow> {
|
||||
key: DataTableKey<Row>;
|
||||
key: DataTableKey<Row> | (string & {});
|
||||
value: DataTableValue;
|
||||
display?: (item: Value, row: DataTableRow) => DataTableValue;
|
||||
}
|
||||
|
|
17
types/DataTable/DataTableTypes.d.ts
vendored
Normal file
17
types/DataTable/DataTableTypes.d.ts
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
type PathDepth = [never, 0, 1, 2, ...0[]];
|
||||
|
||||
type Join<K, P> = K extends string | number
|
||||
? P extends string | number
|
||||
? `${K}${"" extends P ? "" : "."}${P}`
|
||||
: never
|
||||
: never;
|
||||
|
||||
export type PropertyPath<T, D extends number = 10> = [D] extends [never]
|
||||
? never
|
||||
: T extends object
|
||||
? {
|
||||
[K in keyof T]-?: K extends string | number
|
||||
? `${K}` | Join<K, PropertyPath<T[K], PathDepth[D]>>
|
||||
: never;
|
||||
}[keyof T]
|
||||
: "";
|
Loading…
Add table
Add a link
Reference in a new issue