相关疑难解决方法(0)

TS1086:不能在环境上下文中声明访问器

在初始实施后,我在终端 ng serve my-app of 中输入了数千个此错误,但我无法解决它。这对我来说是第一次,当我在 angular 内部遇到这样的问题时,打字稿错误看起来像这样:

../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:24:19 中的错误 - 错误 TS1086:无法在环境上下文中声明访问器。

24     protected get parentElement(): HTMLElement | null;
                     ~~~~~~~~~~~~~
../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:26:19
Run Code Online (Sandbox Code Playgroud)

- 错误 TS1086:无法在环境上下文中声明访问器。

26     protected get nativeElement(): HTMLElement;
                     ~~~~~~~~~~~~~
../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:28:9
Run Code Online (Sandbox Code Playgroud)

- 错误 TS1086:无法在环境上下文中声明访问器。

28     get activatedValue(): string;
           ~~~~~~~~~~~~~~
../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:29:9
Run Code Online (Sandbox Code Playgroud)

- 错误 TS1086:无法在环境上下文中声明访问器。

29     set activatedValue(value: string);
           ~~~~~~~~~~~~~~
../../node_modules/@angular/flex-layout/core/typings/breakpoints/break-point-registry.d.ts:20:9
Run Code Online (Sandbox Code Playgroud)

- 错误 TS1086:无法在环境上下文中声明访问器。 [...]

有人知道原因吗?在我修复它之前,我无法测试我的应用程序。

更新 1

好的,我继续前进。大多数错误都消失了,但我现在有几个错误,例如第一个:

src/app/main/main.component.ts:143:63 中的错误 - 错误 TS2322:键入 'string | undefined' 不能分配给类型 'string'。类型 'undefined' 不能分配给类型 'string'。

第 143 章

代码如下所示:

main.component.ts:

currentRoot: MpFileElement = new …
Run Code Online (Sandbox Code Playgroud)

typescript angular

87
推荐指数
6
解决办法
16万
查看次数

在 Web Worker 中导入 tensorflow 时出现 Angular 打字稿类型检查问题

我正在尝试在 angular 项目的网络工作者中使用 tensorflow/tfjs (TF)。

使用该ng generate worker命令创建 web-worker工作正常。

在组件中导入 TF 也很好。

但是,在工作人员中导入 TF,即:

import * as tf from '@tensorflow/tfjs'
Run Code Online (Sandbox Code Playgroud)

通过ng build命令构建时会生成一堆缺少定义的错误。缺少的类型通常是与 DOM 相关的类型,例如error TS2304: Cannot find name ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement. 这些类型在 TF 的某些定义中使用,据我所知,这些类型不能被 web-workers 访问,因为DOM 操作不能从 workers 完成。我对此非常满意,我对 TF 的使用不依赖于这些类型。但是我仍然需要找到一种方法来构建我的工人。

因此,我试图修补该tsconfig.worker.json文件。我的第一次尝试是通过在compilerOptions.lib数组中添加“dom”来模仿其他 tsconfig* 文件:

["es2018", "webworker"] 
Run Code Online (Sandbox Code Playgroud)

取而代之

["es2018", "webworker", "dom"]
Run Code Online (Sandbox Code Playgroud)

这会导致类型定义冲突

error TS6200: Definitions of the following identifiers conflict with those in another file …
Run Code Online (Sandbox Code Playgroud)

web-worker typescript tsconfig tensorflow angular

6
推荐指数
1
解决办法
313
查看次数

如何使用/声明一个外部模块,该模块不会在 Angular 11 中通过 strict 和 noImplicitReturns TypeScript 设置?

我们有一个开启了严格模式的 Angular 11 应用程序。它在compilerOptions配置中有这些值tsconfig.json

"strict": true,
"noImplicitReturns": true,
Run Code Online (Sandbox Code Playgroud)

现在我们要使用外部库(传单 geoman)。库是这样导入的:

import * as L from 'leaflet';
import '@geoman-io/leaflet-geoman-free';
Run Code Online (Sandbox Code Playgroud)

不幸的是,它包括隐式any类型以及隐式any返回类型:

参数“options”隐式具有“any”类型。
缺少返回类型注释的“setLang”隐式具有“any”返回类型

如何告诉编译器在编译期间忽略模块中的这些错误,但strict在项目的其余部分保持打开模式?

type-hinting typescript typescript-typings angular leaflet-geoman

2
推荐指数
1
解决办法
193
查看次数