首页 > 解决方案 > @typescript-eslint/no-unsafe-assignment - `any` 值的不安全分配

问题描述

我在我的 Angular 项目中使用应用洞察库。我使用 eslint 对代码进行 lint,这确实有助于发现一些奇怪的错误:

@Injectable({ providedIn: "root" })
export class AppInsightsService {
   appInsights: ApplicationInsights;
   constructor() {
      this.appInsights = new ApplicationInsights({   // ====> HERE
         config: {
            instrumentationKey: environment.appInsights.instrumentationKey,
            enableAutoRouteTracking: true
         }
      });
      this.appInsights.loadAppInsights();            // ====> HERE
   }

   logPageView(name?: string, url?: string): void {
      this.appInsights.trackPageView({               // ====> AND HERE
         name,
         uri: url
      });
   }
...
}

但是 lint 在我添加注释的行中显示以下错误:

值的不安全分配any.eslint@typescript-eslint/no-unsafe-assignment)

有人可以解释一下这个appInsights领域有什么问题吗?

标签: typescripttypescript-eslintappinsights

解决方案


推荐阅读