plot icon indicating copy to clipboard operation
plot copied to clipboard

TypeScript declarations

Open cmoog opened this issue 4 years ago • 8 comments

Loving this new API 👍, great work all around.

TypeScript declaration files would be a solid UX improvement, making the API surface even more approachable for new comers.

cmoog avatar May 14 '21 17:05 cmoog

I've never done this but a pull-request, even if it's incomplete, would help to get us started.

In particular I don't know how to test the coverage of ts declarations in CI.

A good starting point is probably the README.md API docs, which is the reference (source of truth).

Fil avatar May 14 '21 20:05 Fil

Because Plot uses D3 under the hood, I believe this would be preceded by having up to date and well maintained TS declarations for D3. Currently the Definitely Typed package has some pain points that I've run into when using TypeScript with D3, which I imagine would affect the TS declarations for Plot.

clhenrick avatar Jun 04 '21 23:06 clhenrick

Because Plot uses D3 under the hood, I believe this would be preceded by having up to date and well maintained TS declarations for D3. Currently the Definitely Typed package has some pain points that I've run into when using TypeScript with D3, which I imagine would affect the TS declarations for Plot.

@Fil @clhenrick I've been experimenting with type declarations for Plot, so I'd like to know if any of the pain points that you referred to have been resolved with the recent work on the D3 types.

I'm referring to these updates:

  • DefinitelyTyped/DefinitelyTyped#38939
  • https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56119
  • https://github.com/DefinitelyTyped/DefinitelyTyped/pull/54021
  • https://github.com/DefinitelyTyped/DefinitelyTyped/pull/54044
  • https://github.com/DefinitelyTyped/DefinitelyTyped/pull/54101

kentr avatar May 16 '22 20:05 kentr

Thank you for the work you are doing on d3 types! I'd be happy to see your experiments with Plot.

Fil avatar May 16 '22 20:05 Fil

@Fil Ah, I mixed up my previous reply. I thought that the comment I quoted was from you, but now I see that it was not.

Those D3 updates are the work of some other wonderful people. I can't claim any credit for them. I'll create a PR for the Plot type experiments. They are very new, so it will be more of a starting point as you suggested than an actual request to merge.

kentr avatar May 16 '22 20:05 kentr

Does Plot work with typescript or not? I'm getting errors.

sgehrman avatar Aug 12 '22 03:08 sgehrman

@sgehrman It does work with typescript, although there are no type declarations (as far as I know).

If you want to remove the type errors, what I've done to get it working is to create a file in your project declaring the types. For me that looks like the following:

// file /types/untypedDependencies.d.ts
declare module '@observablehq/plot'

It would be great to have types to get code completion and better linting though :)

dgrcode avatar Aug 19 '22 11:08 dgrcode

If you want to remove the type errors, what I've done to get it working is to create a file in your project declaring the types.

Same for me.

It would be great to have types to get code completion and better linting though :)

The project has started converting files to TypeScript, ~~but it looks like those files aren't in a release yet~~.

Edit: I was wrong. There are some TS files in a release.

kentr avatar Aug 30 '22 01:08 kentr

Fixed in #1320! And more documentation to follow immediately.

mbostock avatar Mar 13 '23 17:03 mbostock

Released in 0.6.5.

mbostock avatar Apr 01 '23 23:04 mbostock

Wow, I just tried these out and they are incredible! The types, documentation, everything!

cmoog avatar Apr 02 '23 14:04 cmoog