edtf.js icon indicating copy to clipboard operation
edtf.js copied to clipboard

Add basic TypeScript declaration files (first pass)

Open singingwolfboy opened this issue 10 months ago • 0 comments

First attempt at fixing #49.

I'm pretty decent at writing TypeScript, but I have less experience with writing TS declaration files, and I don't know the logic of this codebase well enough to add correct annotations everywhere. Therefore, in order to make this pull request, I did the following:

  1. Forked the repo to singingwolfboy/edtf.ts
  2. Renamed all the *.js files to *.ts, and added the TypeScript dependency to package.json
  3. Spent some time looking through the codebase, annotating types where I could -- including making educated guesses when I didn't entirely understand what the code was doing
  4. Committed my type annotations to my fork (where they are still visible)
  5. Ran npx tsc --declaration --emitDeclarationOnly to make TypeScript generate the declaration files for me
  6. Made a new branch off of the latest code in inukshuk/edtf.js, added a commit with those declaration files, and made this pull request

Some important caveats:

  • I have not done any testing that these declaration files get picked up correctly by developers using TypeScript. This pull request should be considered a quick "first pass" implementation, not a tested & polished final implementation.
  • I have not added type annotations to every file. I mostly focused on parser.js, interface.js, and date.js. There are plenty of any types in these declaration files, which can (and probably should!) be narrowed to something more specific.

If you are not interested in merging this pull request as a result of the above caveats, I completely understand. My goal is to demonstrate how we might start to add types to this codebase, in the hopes of inspiring others to complete a more robust implementation. I intend to keep my fork up on GitHub, so that others can view the TypeScript annotations in the code, and maybe fork my work and continue it to completion.

singingwolfboy avatar Jan 05 '25 14:01 singingwolfboy