nba icon indicating copy to clipboard operation
nba copied to clipboard

TypeScript type definitions

Open garyking opened this issue 6 years ago • 4 comments

It would be great to have TypeScript type definitions for this library. Thanks!

garyking avatar Jan 09 '20 03:01 garyking

doing the argument signature would be doable but getting types on the API response shapes would be a lot of work without some kind of tool to automate it. I don't have a lot of time at the moment, but might take a stab at this later, or PRs are welcome!

bttmly avatar Jan 10 '20 21:01 bttmly

I've created types just for the methods I'm using, for myself. I use http://json2ts.com/ to create the API response types.

I can tell you that the types are a mess though. Like, some endpoints will return a different format for the same property name.

garyking avatar Jan 11 '20 01:01 garyking

Yeah I've noticed that they seem to have rather lax standards for API development and consistency.

bttmly avatar Jan 13 '20 23:01 bttmly

EDIT: I figured it out, should have types soon.


@garyking do you have any experience writing d.ts files for javascript libraries? I started a branch to add strong types but I can't seem to figure out how to export what I want. The docs for writing d.ts files are strangely sparse; there are a lot of articles but they're old; not a lot of authoritative information that I could find.

If you check out that branch, you can generate the underlying types for each data endpoint with this:

WRITE_RESPONSES=1 yarn run mocha test/integration/data.js; node ./scripts/makeTypes.js

the library I used https://github.com/jvilk/MakeTypes seems to put out somewhat better definitions than http://json2ts.com/

bttmly avatar Mar 21 '20 04:03 bttmly