{"library":"musickit-typescript","title":"MusicKit TypeScript Types","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install musickit-typescript"],"cli":null},"imports":["const musicInstance = MusicKit.getInstance();","let api: MusicKit.API;","function initializePlayer(player: MusicKit.Player) { /* ... */ }"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"npm install --save-dev musickit-typescript\n\n// Then, update your tsconfig.json:\n// Make sure 'node_modules/musickit-typescript' is included in 'typeRoots'\n// alongside 'node_modules/@types' to ensure TypeScript finds the definitions.\n{\n  \"compilerOptions\": {\n    \"typeRoots\": [\n      \"node_modules/musickit-typescript\",\n      \"node_modules/@types\"\n    ],\n    \"target\": \"es2018\",\n    \"module\": \"esnext\",\n    \"lib\": [\"dom\", \"esnext\"]\n  },\n  \"include\": [\"src/**/*.ts\"]\n}\n\n// Example usage in your TypeScript file (assuming MusicKit JS is loaded in HTML):\n// Make sure to define your developer token or get it from your backend\ndeclare const MusicKit: MusicKit.MusicKitInstance;\nconst developerToken = process.env.APPLE_MUSIC_DEV_TOKEN ?? 'YOUR_DEVELOPER_TOKEN_HERE';\n\nasync function initMusicKit() {\n  try {\n    await MusicKit.configure({\n      developerToken: developerToken,\n      app: {\n        name: 'My Awesome App',\n        build: '1.0.0'\n      }\n    });\n    const music = MusicKit.getInstance();\n    console.log('MusicKit initialized successfully:', music);\n    if (music.isAuthorized) {\n      console.log('User is authorized.');\n    } else {\n      console.log('User is not authorized. Requesting authorization...');\n      await music.authorize();\n      console.log('User authorized!');\n    }\n    const player: MusicKit.Player = music.player;\n    console.log('Current playback state:', player.playbackState);\n  } catch (error) {\n    console.error('Failed to initialize MusicKit:', error);\n  }\n}\n\ninitMusicKit();\n","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}