为什么 reflect-metadata 仅在使用装饰器时有效?

Why is reflect-metadata only working when using a decorator?

没有装饰器,元数据就会丢失 - 但为什么呢?

const Baz = () : ClassDecorator => {
  return target => {}
}
class Bar {}
@Baz()
class Foo {
  constructor(bar: Bar) {}
}
console.log(Reflect.getMetadata('design:paramtypes', Foo));

这个returns[Function: Bar],很好。但是如果没有 @Baz 装饰器(实际上什么都不做)它 returns undefined。为什么?

实现此功能的 PR 指出:

emit design-time type metadata for decorated declarations in source.

所以它被明确设计为只要 class 上有装饰器就可以发出元数据。

我无法找到此决定背后的基本原理,但我猜想为所有 classes(js 对大小敏感)发出此代码会很浪费,并且可以看到装饰器和元数据作为相关概念。