This package provides TypeScript type definitions for Apple's MusicKit JS library. It enables developers to use TypeScript with the MusicKit JS API, offering compile-time type checking and improved IDE autocompletion, which is crucial as the official MusicKit JS library might lack comprehensive native types. The current stable version is 1.2.4. As a type definition package, its release cadence is typically tied to updates or community needs concerning the MusicKit JS library itself rather than following a fixed schedule. It serves as a community-driven effort to enhance the developer experience for those integrating Apple Music into web applications using TypeScript.
npm install musickit-typescriptVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install the types and configure `tsconfig.json`. It then shows how to access the global `MusicKit` object and use its types for initialization and basic player interaction, assuming the MusicKit JS library is loaded in the browser.
Ensure that `typeRoots` in your `tsconfig.json` includes `"node_modules/musickit-typescript"` alongside `"node_modules/@types"` (if present) to correctly inform the TypeScript compiler about where to find these ambient declarations.
Regularly check the `musickit-typescript` GitHub repository or `npm` for updates. If issues arise, cross-reference the types with the official MusicKit JS documentation to identify discrepancies.
Ensure that the official MusicKit JS library is properly loaded into your application's environment before attempting to use the `MusicKit` global object at runtime. This typically involves including a `<script>` tag for the MusicKit JS SDK in your HTML.
Verify that your `tsconfig.json` file includes `"node_modules/musickit-typescript"` in the `typeRoots` array. For example: `"typeRoots": ["node_modules/musickit-typescript", "node_modules/@types"]`.
Ensure that the official Apple MusicKit JS library is loaded via a script tag in your HTML document (or equivalent method for your environment) before your application code attempts to access `MusicKit`.
Check for an updated version of `musickit-typescript`. If an update is not available or the method is custom, you may need to create a local declaration file (`.d.ts`) to augment the existing types, for example: `declare namespace MusicKit { interface Something { someNewMethod(): void; } }`.