[英]TS2364: Invalid left-hand side of assignment expression
a
is a mutable array, so why can't I assign to it? a
是一个可变数组,为什么我不能分配给它?
export let a: any[];
import {a} from './foo';
a = [5,6,7];
a
contains a mutable array, so you can mutate it: a
包含一个可变数组,所以你可以改变它:
a.splice(0, a.length, 5, 6, 7);
console.log(a);
a
in bar
is an imported binding however, and those cannot be reassigned. a
在bar
被导入的结合然而,这些不能被重新分配。 That's why it's a syntax error. 这就是为什么它是一个语法错误。
You can assign to a
in foo
however, where it's just behaving like a normal variable. 您可以分配到
a
在foo
然而,如果它只是表现得像一个正常的变量。
If you want to be able to change the value of the array inside the original scope ( foo.ts
) then you can do something like: 如果您希望能够在原始范围(
foo.ts
)中更改数组的值,那么您可以执行以下操作:
export var a = {
arr: []
}
and then in bar.ts
: 然后在
bar.ts
:
import {a} from './foo';
a.arr = [5,6,7];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.