Skip to content

Convert the source to TypeScript #85

Description

@mapitman

Convert the source under lib/ and the gettyimages-api.js entry point from JavaScript to TypeScript.

Why

The main argument is that this collapses work already planned in this milestone, rather than adding to it.

It provides the build step #64 needs. Dual ESM and CommonJS output requires a build. tsc is that build. Without this conversion, #64 adds a build step purely to transform module syntax, which is a lot of machinery for very little gain.

It removes the hand-written declarations. gettyimages-api.d.ts is 572 lines describing roughly 2,000 lines of untyped JavaScript, and nothing enforces that the two agree. types-test.ts checks that the declarations compile; it does not check them against the implementation. Add a builder method and forget the declaration file, and no test fails. Generated declarations cannot drift.

It verifies #65. Marking execute() as async is a contract change across 14 methods. The compiler confirms it landed consistently.

It deletes the WeakMap boilerplate. Every class carries roughly 20 lines of this pattern:

const _ids = new WeakMap();
set ids(value) { _ids.set(this, value); }
get ids() { return _ids.get(this); }

TypeScript's private fields replace it. lib/images.js is 80 lines today and should land near 45.

Scope

  • 18 files under lib/, plus gettyimages-api.js. Roughly 2,000 lines, of which about half is repetitive fluent builders that convert mechanically.
  • Roughly 20 test files, 1,800 lines.
  • Replace jsconfig.json with a real tsconfig.json, and generate declarations with declaration: true.
  • Delete the hand-written gettyimages-api.d.ts once the generated output matches it. Keep types-test.ts as a consumer-facing check against the generated declarations.
  • Replace the WeakMap private-field pattern with private fields.
  • lib/webhelper.js uses the WebHelper function-constructor style, unlike the class style used everywhere else. Normalize it during the conversion.

Out of scope

Typing the API responses. Every execute() returns Promise<any> today, and it should continue to after this change. Modeling the Getty API response shapes is a much larger job than converting the request builders, and it belongs in its own issue.

Sequencing

Do this first in the milestone, ahead of #65 and #64.

Doing #64 or #65 in JavaScript first means redoing parts of both.

Notes

  • This is not user-visible. Consumers already have typings, as of the declarations added for Typescript Support? #56. This change buys maintainer confidence and enables the rest of the milestone; it does not add consumer capability on its own.
  • Cost to weigh: contributors will need TypeScript to submit a PR. That is a real, if modest, barrier for an SDK that takes occasional outside contributions.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions