But in TypeScript, this generates an error:
但是在TypeScript中,这会产生一个错误:
The property 'prop' does not exist on value of type '{}'
类型“ {}”的值不存在属性“ prop”
How am I supposed to assign any new property to an object in TypeScript?
我应该如何在TypeScript中为对象分配任何新属性?
参考:
https://stackoom.com/question/RkGB/如何在TypeScript中为对象动态分配属性
Although the compiler complains it should still output it as you require.
尽管编译器抱怨它仍应按您的要求输出。
However, this will work.
但是,这将起作用。