Repository navigation
Type Spotify API responses - #239
Merged
Merged
Conversation
Add hand-written types in src/spotify.ts for the responses the app reads, checked against the recorded fixtures through the typed test builders. Type the export config, the Liked Songs pseudo-playlist and the unloaded playlist placeholder, and re-enable @typescript-eslint/no-explicit-any. Use a btn-xs class and inline Font Awesome icon tuples instead of the @ts-expect-error workarounds. Blank the artist names of podcast episodes, which Spotify sends as null and the CSV wrote out as "null". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Spotify documents playlist public as nullable, which @types/spotify-api models and the hand-written types didn't. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Adds hand-written TypeScript types for the Spotify responses the app reads (
src/spotify.ts), types the export config (ExportConfig) and the Liked Songs pseudo-playlist (LikedSongsPlaylist), removes every@ts-ignoreand@ts-expect-error, and re-enables@typescript-eslint/no-explicit-any. Oneanyremains, in the fixture scrubber, which handles raw captures from any endpoint.The types are modelled on the recorded fixtures rather than the docs, including the nullable cases the app handles: null tracks, local tracks, null
added_by, nullpreview_urland ISRC, null playlistimages, nullowner.display_name, nullpublic, and null entries in/albumsand/audio-features. The test builders annotate each fixture template with its type, so the compiler checks the types against the real responses.Typing also showed that CSV cells hold numbers and booleans as well as strings. They're now typed as
CsvValue, with no change to the output.Hand-written types vs
@types/spotify-apiI tried basing the types on
@types/spotify-api@0.0.26:PagingObjectfitted as it is. The other 13 of the 14 object types needed overrides, 49 fields in all, and every batch and error response wrapper still had to be written locally. Assigning the fixtures to the raw package types failed for all 9 that were checked./meis typed as the private profile, which requiresemail,country,productandbirthdate. We never request those scopes.nameis null and the show's name is in artisttype, but the package hasname: stringandtype: "artist".external_urls. The package types all of these as present.imagescan be null.owner.display_nameandadded_bycan be null./albumsand/audio-featuresreturn null entries.typefields don't type-check against fixtures imported from JSON.The package did show that the playlist
publicis nullable in Spotify's docs. That's ported to the hand-written types in b7203b5.Behaviour change: episode artist names
Typing exposed a bug. For podcast episodes in a playlist, Spotify sends the artist (the show) with
name: null, and the CSV wrote the literal textnullinto the Artist Name(s) and Album Artist Name(s) columns. Those cells are now blank. Only episode rows change.🤖 Generated with Claude Code + hand edited