本文介绍了升级到Angular 9后,在打字文件中找不到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我引用了我在类型文件中定义的外部日志记录组件(在js文件中引用)

I have a reference to an external logging component (referenced in a js file), which I have defined in a typings file

typings.d.ts

declare var LogglyTracker;

我已将我的角度应用程序从版本8升级到了9,现在运行 ng build 时,出现以下错误

I have upgraded my angular application from version 8 to 9, and now when I run ng build, I get the following error

有人知道解决此问题的推荐方法是什么吗?这段代码在Angular 8中运行良好.

Does anyone know what the recommended way to fix this problem is? This code worked fine in Angular 8.

@Injectable()
export class LogglyLoggerService {

// https://github.com/loggly/loggly-jslogger
private loggly: any = new LogglyTracker(); //!! Error here
}

推荐答案

对我来说,解决方法是在服务文件顶部添加以下内容:

Well for me the resolution was to add the following to the top of service file:

/// <reference path="../../typings.d.ts" />

引用显然是将类型定义导入代码的另一种方法,更多信息这里

reference is apparently another way to import type definitions into code, more info here

这篇关于升级到Angular 9后,在打字文件中找不到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:44