plot icon indicating copy to clipboard operation
plot copied to clipboard

ts options

Open Fil opened this issue 3 years ago • 3 comments

Typescript for data (the expected shapes of data) and options (valueof, arrayify), with tooling and unit tests.

Was researched initially in #1008, and confirmed to work with all the transforms and more in #1005.

Fil avatar Aug 08 '22 14:08 Fil

Thanks for testing this Michael! Here are a few cases that seem to work for me. Capture d’écran 2022-08-08 à 18 27 54

However I don't have autocompletion on the empty string, which I think used to work in an earlier stage 😅

Fil avatar Aug 08 '22 16:08 Fil

A related error is that the popup here says that the value is null | undefined, when it will actually be an array of undefined

Capture d’écran 2022-08-23 à 14 36 26

Fil avatar Aug 23 '22 12:08 Fil

@@ -16,7 +16,8 @@ export type Row = Record<string, Value>;
  */
 export type Datum = Row | Value | Value[];
 export type FieldNames<T> = T extends Row
-  ? keyof T
+  ? // eslint-disable-next-line @typescript-eslint/ban-types
+    keyof T | (string & {})
   : T extends Value[]
   ? // eslint-disable-next-line @typescript-eslint/ban-types
     "length" | "0" | "1" | "2" | (string & {})

With this patch, we get autocomplete to work again, and the issue or "wrongfully giving undefined | null" above goes away too. However the price to pay is that we lose the ts error on: valueof([{one: "one", two: "two"}], "red");

I think this makes sense.

Fil avatar Aug 23 '22 12:08 Fil

I hope we can restart work on this soon, with a simpler approach (not trying to pass the shape of data through all the code).

Fil avatar Feb 06 '23 13:02 Fil

Probably superseded by #1320 which goes the d.ts route, but would be nice to repurpose the type tests here?

mbostock avatar Mar 13 '23 17:03 mbostock

l33t tests at #1337

Fil avatar Mar 14 '23 15:03 Fil