memoji

Jonathan Foster

@fostertheweb

Deprecate Function Argument in TypeScript

Last Updated: 2024-01-27 17:03:31 UTC

In fostertheweb/spotify-web-sdk, the method for obtaining a token with client credentials for non-user actions incorrectly accepted an argument for scopes. Scopes only apply to user authorization for requesting permission from a user to perform various actions via the Spotify API. To maintain backwards compatibility I added two overloads. One to inform developers in their editor without breaking their build and the other defining the new signature without scopes.

public static withClientCredentials(
  clientId: string,
  clientSecret: string,
  config?: SdkOptions
): SpotifyApi;

\* @deprecated The scopes array is not used for client authorization. Remove the argument. */
public static withClientCredentials(
  clientId: string,
  clientSecret: string,
  config: SdkOptions,
  scopes: string[]
): SpotifyApi;

public static withClientCredentials(
  clientId: string,
  lientSecret: string,
  config?: SdkOptions
): SpotifyApi {
  const strategy = new ClientCredentialsStrategy(clientId, clientSecret);
  return new SpotifyApi(strategy, config);
}

Now when you add that last argument to the method you will get feedback in your editor. If you don’t provide the argument it works as expected.

screenshot of tooltip in vs code showing deprecated method argument

You can see the above snippet in the context of the library code.

Hope this helped!

Share some tips with me on Twitter