角度:找不到名称空间"Spotify"使用@ types/spotify-web-playback-sdk时 [英] Angular: Cannot find namespace "Spotify" when using @types/spotify-web-playback-sdk

查看:96
本文介绍了角度:找不到名称空间"Spotify"使用@ types/spotify-web-playback-sdk时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 https://www.我的有角项目中的npmjs.com/package/@types/spotify-web-playback-sdk 可以在我的组件之一中键入Spotify播放器.我按照指示安装了这些类型...

I'm trying to use https://www.npmjs.com/package/@types/spotify-web-playback-sdk in my angular project to type out the spotify player in one of my components. I Installed the types, as instructed...

npm install --save @types/spotify-web-playback-sdk

当我定义此类变量并将其键入SpotifyPlayer时,Visual Studio代码linter不会抱怨...

The Visual Studio code linter doesn't complain when I define this class variable and type it to a SpotifyPlayer ...

// class variable
spotifyPlayer: Spotify.SpotifyPlayer;

但是,当我构建代码时,出现此错误...

But, when I go to build my code, I get this error...

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

感谢帮助!

推荐答案

按照类型定义这里,您将直接在 html 中添加 JS包,这意味着此 Script 不会作为<代码>模块.

As per the type definition here spotify-web-playback-sdk is non-npm package. As per the Spotify documentation here, you would be adding the JS bundle in your html directly, which means this Script is not loaded as a module.

来自绝对键入

如果您不使用模块,则可能需要添加类型引用

You may need to add a types reference if you're not using modules

您可以将以下行添加到使用 Spotify名称空间的文件的顶部,该错误应会消失.

You can add the below line to top of the file where you are using Spotify namespace and the error should disappear.

///  <reference types="@types/spotify-web-playback-sdk"/>

更多信息,请此处此处.每当Spotify发布npm库时,建议改用该库.

More information is here and here. Whenever Spotify publishes a npm library prefer using that instead.

这篇关于角度:找不到名称空间"Spotify"使用@ types/spotify-web-playback-sdk时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆