我正在尝试使用 https://www.npmjs.com/package/@types/spotify-web-playback-sdk在我的 Angular 项目中,在我的组件之一中输入 Spotify 播放器。我按照说明安装了类型...
npm install --save @types/spotify-web-playback-sdk
当我定义此类变量并将其输入到 SpotifyPlayer 时,Visual Studio 代码 linter 不会提示...
// class variable
spotifyPlayer: Spotify.SpotifyPlayer;
但是,当我去构建代码时,我收到此错误......
ERROR in src/app/components/header/header.component.ts:32:18 - error TS2503: Cannot find namespace 'Spotify'.
32 spotifyPlayer: Spotify.SpotifyPlayer;
我正在使用...
Angular CLI: 9.1.0
Node: 10.15.1
OS: win32 x64
Angular: 9.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.901.0
@angular-devkit/build-angular 0.901.0
@angular-devkit/build-optimizer 0.901.0
@angular-devkit/build-webpack 0.901.0
@angular-devkit/core 9.1.0
@angular-devkit/schematics 9.1.0
@ngtools/webpack 9.1.0
@schematics/angular 9.1.0
@schematics/update 0.901.0
rxjs 6.5.4
typescript 3.8.3
webpack 4.42.0
感谢您的帮助!
最佳答案
根据类型定义here spotify-web-playback-sdk
是非 npm 包
。
根据 Spotify
文档 here ,您将直接在 html
中添加 JS 包
,这意味着此 Script
不会作为 模块
加载>.
You may need to add a types reference if you're not using modules
您可以将以下行添加到使用 Spotify 命名空间
的文件顶部,错误就会消失。
/// <reference types="@types/spotify-web-playback-sdk"/>
关于javascript - Angular:使用 @types/spotify-web-playback-sdk 时找不到命名空间 "Spotify",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61039624/