首页 > 解决方案 > Typescript 在我的 Angular 项目中找不到 @types/spotify-api

问题描述

我安装@types/spotify-api并对我的 tsconfig.json 进行了以下更改

"typeRoots": [
  "node_modules/@types"
],
"types": [
  "spotify-api"
],

例如,打字稿找不到PlaylistTrackResponse。我不知道为什么,因为它与@types/node其他项目中的类型的工作方式相同。我正在使用打字稿 3.7.5。

我完整的 tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
      "spotify-api"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "disableTypeScriptVersionCheck": true
  }
}

标签: typescript

解决方案


不知道您是否还需要回答这个问题,因为您很久以前就问过这个问题,但您可以通过以下方式解决这个问题:

/// <reference types="spotify-api" />

在你班级的顶部,然后得到任何类型,如下所示:

SpotifyApi.PlaylistObjectSimplified

推荐阅读