问题标签 [reflect-metadata]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
angular - Angular 元数据 ImportAs
好奇是否有人拥有或知道如何获取有关 Angulars 使用元数据的更多信息?具体来说,我正在寻找 Angular 使用 importAs 属性的内容和位置?它是在使用 flatModuleId 的 angularCompilerOptions 标志时在元数据中创建的。根据我可以收集到的信息,当从 npm 模块中的组件库导入时,编译器似乎使用它来获取有关模块和/或组件的元数据。我可以在任何地方阅读有关此内容的更多信息都会非常有帮助,谢谢。
typescript - After typescript update 2.3.4 => 2.4.2 i get compilation error "Cannot find type definition file for 'reflect-metadata'."
I have a React / Mobex application written in TypeScript, built by Webpack 1. After updating TypeScript version from 2.3.4 to 2.4.2 i get an error
I also tried Typescript 2.7.2, same error. I've tried explicitly providing the path to its typings in "paths"
, tried installing the latest version of 'reflect-metadata'
, including globally - still same error.
tsconfig.json
package.json
node.js - 为什么 TypeORM 需要反射元数据?
我目前正在使用 Node 学习 TypeScript。阅读有关 TypeORM 的信息,我看到reflect-metadata
TypeORM 需要该包才能工作。需要这个包的原因是什么?
typescript - 打字稿不发出装饰器元数据
我有一个打字稿项目,想检查一些对象。所以我安装reflect-metadata
、启用experimentalDeorators
并emitDecoratorMetadata
在tsconfig.json
. 然后我有这个代码:
它输出undefined
. 我希望得到String
或其他东西。此外,编译后的 Javascript 如下所示:
没有设置元数据的代码。有趣的是,在我添加自定义装饰器的那一刻,我看到为设置元数据发出的代码:
但我还是明白了undefined
。我也试过了Bla.prototype
,没有变化。知道这里有什么问题吗?
angular - 如何获取绑定 [(ngModel)] 的属性名称?角6
我有以下自定义组件
在这种情况下,如何从类中获取属性名称“prop1”?
角度不知何故知道它应该更新哪个属性。我想获取此属性的引用或名称。谢谢
typescript - 无法获取类实例的反映元数据
我正在尝试从类的实例中检索反射元数据。文档上的示例表明它应该是可能的,但我得到了undefined
. 但是,如果我从类本身请求元数据,我会取回数据,与方法相同。
例如,这是完整的示例脚本:
我的目标是取回一些数据classInstanceMetadata
,让我将其与类类型相关联。
typescript - How to import reflect-metadata correctly
So I have a TypeScript project I am working on and I want to make use of the reflect-metadata package. I am a little confused about the correct way of importing this. It was my understanding that this only needed to be imported once in your "main" file. So in my case I have an app.ts in which I import reflect-metadata as the very first thing:
ReflectionClass
then in turn imports another class that eventually calls Reflect.getMetadata()
. However, this fails with error
Only when I import reflect-metadata explicitly in the relevant file does the error disappear. Is this the correct way to do this? In other words, do I need to import reflect-metadata in each file that uses it as opposed to a global, one time import in your main file?
typescript - 当返回类型为 Promise of something 时,使用 reflect-metadata 获取返回类型
当函数返回类型为时Promise<number>
,我如何通过反射获得它?
如果我只是这样做
它只是返回Promise
,所以有办法知道那是数字的承诺吗?
typescript - 如何从方法装饰器访问类装饰器的参数
我想使用从同一类的方法装饰器传递给类装饰器的信息。这是(虚拟)类的样子:
现在我有兴趣在 methodDecorator 中使用给 classDecorator ( {something: very interesting'}
) 的参数。
我希望我可以使用 Reflect API,但无济于事:
是否可以从同一类的 methodDecorator 中访问 classDecorator 的参数?
typescript - 打字稿装饰器 + 反映元数据
我正在使用一个属性装饰器Field
,它将它的键推送到fields
反射元数据属性:
然后,我有一个抽象基类Form
,可以访问 getter 附件中的元数据:
到目前为止,我已经能够成功地使用它来区分表单字段和其他类属性。考虑这些类:
当我将姐妹类定义为AdminForm
-时,就会出现问题MemberForm
。当存在多个子类时, getterForm
似乎fields
返回所有字段:
这对我来说毫无意义。为什么该memberSince
字段出现在 的实例上AdminForm
?如何在不同的子类上定义不同的字段?