javascript - 错误 TS2539 : Cannot assign to 'c' because it is not a variable

标签 javascript typescript

我有 2 个 .ts 文件,

C.ts:

export let c: any = 10;

A.ts:

import { c } from "./C";
c = 100;

编译A.ts时报错:

error TS2539: Cannot assign to 'c' because it is not a variable.

我该如何解决?

最佳答案

将它放在一个类中,并使其成为静态的

export class GlobalVars {
  public static c: any = 10;
}

从任何其他文件导入之后

GlobalVars.c = 100;

关于javascript - 错误 TS2539 : Cannot assign to 'c' because it is not a variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45997225/

相关文章:

javascript - x 轴上的时间显示从当前时间算起的最后 24 小时

javascript - 为什么 org/arangodb/request 是同步的?

javascript - templateURL 的 AngularJS 问题

javascript - 使用 transition.end() promise 链接转换

javascript - Gatsby.js : how to migrate all *. js文件到*ts?

javascript - 传递、访问或预填充数据时遇到问题 - Vue.js/Firestore

javascript - NestJS 在非模块文件中注入(inject)模块服务

angular - 在 Angular 中,当http响应具有对象数组时如何使用适配器模式?

typescript - Array.isArray 检查不足以让编译器完全了解 TypeScript 中可能的数组值

Javascript、Typescript、Angular 5 - 打开和读取文件