Add TypeScript declarations for the existing public surface - #84
Merged
Conversation
Declare the client, the fourteen request classes, and their fluent builders in a single root gettyimages-api.d.ts, and point the "types" field at it. This covers only what the SDK supports today: no response models, no new operations, and no literal-union enums for values the SDK never enumerates. No runtime code changes, so JavaScript consumers are unaffected. The risk that does exist is a declaration too strict for a call the SDK already accepts, which would break TypeScript consumers at compile time. Three cases drove the signatures: - Builders named in the singular, such as withCollectionCode, are called with arrays throughout the tests, so they accept a value or an array. - Identifier builders, such as withKeywordId, are called with numbers as well as strings. - execute() returns Promise<any>, because Promise<unknown> would force every existing consumer to cast before reading a response field. types-test.ts exercises every builder in the argument forms the AVA tests and the README use. It runs under "npm run test:types" and in CI, so an over-strict signature fails the build rather than reaching consumers. Closes #56
ChrisSimmons
approved these changes
Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #56.
Adds hand-written type declarations for the SDK as it exists today. Scope is deliberately narrow: only the things the SDK already supports. No response models, no new operations, no new types beyond what is needed to describe the current surface.
What changed
gettyimages-api.d.ts— a single root declaration covering the client, the fourteen request classes, and theGettyApiRequestbase.package.json— adds"types", atest:typesscript, andtypescriptplus@types/nodeas dev dependencies.types-test.tsandtsconfig.types.json— a compile-time test, run bynpm run test:types..github/workflows/lint.yml— atypesjob so the check runs on every pull request..npmignore,.eslintignore,README.md— housekeeping for the new files.No changes to
lib/orgettyimages-api.js.Backwards compatibility
Declaration files are erased at runtime and no runtime code moved, so JavaScript consumers cannot be affected.
The risk that does exist is a declaration that is too strict and rejects a call the SDK accepts. For anyone currently on
dts-genoutput, that would turn working code into a compile error. Three findings from reading the implementation against the tests shaped the signatures:withCollectionCode,withFileType,withResponseFieldand others are named in the singular, but the tests call them with arrays such aswithCollectionCode(["WRI", "ARF"]). The implementation appends the whole array andaddParameterjoins it. These are typedstring | string[].withKeywordId([1234, 5678]),withEntityUris([123, 456])andwithProductId(5678), while other call sites pass strings. These are typedstring | number | Array<string | number>.execute()returnsPromise<any>. The SDK returns raw parsed JSON and defines no response models.Promise<unknown>would force every consumer to cast before readingresponse.images[0], which the README does throughout.The entry point uses
export = GettyImagesApi, matching the CommonJSmodule.exports =, so bothimport api from "gettyimages-api"andrequirekeep working.Verification
npm test— 165 tests pass, unchanged.npm run test:types— passes understrict.npm run lint— clean.npm pack --dry-run— the.d.tsships; the test harness does not.withCollectionCodetostring, narrowingwithKeywordIdtostring, switchingexecute()toPromise<unknown>, and switching toexport defaulteach fail the build.any.🤖 Generated with Claude Code