spfx 扩展无关的 ApplicationCustomizerContext 类型 tsc 错误

spfx extension unrelated ApplicationCustomizerContext type tsc error

我在使用 TypesSript

处理 ApplicationCustomizerContext 类型时遇到了困难

1) 我已经创建了一个 spfx 应用程序定制器

2) 我在应用程序定制器主 ts 文件中添加了:

import ApplicationCustomizerContext from "@microsoft/sp-application-base/lib/extensibility/ApplicationCustomizerContext";

3) 并在其 onInit() 方法中添加:

 var ctx: ApplicationCustomizerContext = this.context;

TypeScript 编译器(版本 2.4.2)出现错误:

error TS90010: Type 'ApplicationCustomizerContext' is not assignable to type 'ApplicationCustomizerContext'. Two different types with this name exist, but they are unrelated.

你是否偶然知道应该如何将导入定义为打字稿没有抱怨?

补充信息: 该项目是使用“@microsoft/generator-sharepoint 1.5.1

生成的
"environment": "spo",
"version": "1.5.1",
"packageManager": "npm",
"componentType": "extension",
"extensionType": "ApplicationCustomizer"

tsconfig.json 保持不变(与最初生成的一样)

  "compilerOptions": {
    "target": "es5",
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "jsx": "react",
    "declaration": true,
    "sourceMap": true,
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "typeRoots": [
      "./node_modules/@types",
      "./node_modules/@microsoft"
    ],
    "types": [
      "es6-promise",
      "webpack-env"
    ],
    "lib": [
      "es5",
      "dom",
      "es2015.collection"
    ]

与在 1.4.1 中完成的方式相比,在 SPFx v1.5.1 中完成 ApplicationCustomizerContext 导入的方式似乎有一些变化

修改您的导入语句如下:

import { ApplicationCustomizerContext } from "@microsoft/sp-application-base";