TypeScript中的'const'关键字

tau*_*isv 6 typescript

为什么类成员不能在TypeScript中使用'const'关键字?

我在TypeScript文档网站上找不到任何有用的信息.

bas*_*rat 5

为什么类成员不能在TypeScript中使用'const'关键字?

const 并不意味着深刻的不变性,所以以下是有效的:

const foo:any = {};
foo.bar = 123;  // Okay
Run Code Online (Sandbox Code Playgroud)

在这种意义上,readonly对于类成员更有意义并得到支持:https://basarat.gitbooks.io/typescript/content/docs/types/readonly.html