You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
Expose execute() as async #65 (async execute()) is easier afterwards, because the compiler verifies the change across all 14 methods.
Support both ESM and CommonJS #64 (dual ESM and CommonJS) becomes mostly a tsconfig output setting plus the exports map, because the build step already exists.
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.
Convert the source under
lib/and thegettyimages-api.jsentry 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.
tscis 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.tsis 572 lines describing roughly 2,000 lines of untyped JavaScript, and nothing enforces that the two agree.types-test.tschecks 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:
TypeScript's
privatefields replace it.lib/images.jsis 80 lines today and should land near 45.Scope
lib/, plusgettyimages-api.js. Roughly 2,000 lines, of which about half is repetitive fluent builders that convert mechanically.jsconfig.jsonwith a realtsconfig.json, and generate declarations withdeclaration: true.gettyimages-api.d.tsonce the generated output matches it. Keeptypes-test.tsas a consumer-facing check against the generated declarations.WeakMapprivate-field pattern withprivatefields.lib/webhelper.jsuses theWebHelperfunction-constructor style, unlike theclassstyle used everywhere else. Normalize it during the conversion.Out of scope
Typing the API responses. Every
execute()returnsPromise<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.
execute()) is easier afterwards, because the compiler verifies the change across all 14 methods.tsconfigoutput setting plus theexportsmap, because the build step already exists.Doing #64 or #65 in JavaScript first means redoing parts of both.
Notes