简体   繁体   English

在打字稿中,属性装饰器可以推断出可选类型吗?

[英]In typescript can a property decorator infer an optional type?

In typescript, can a property decorator infer an optional type? 在打字稿中,属性装饰器可以推断出可选类型吗?

Ie If you have the following: 即如果您具有以下条件:

@Column()
ua?: string

Could @Column() recognise that ua is an optional type? @Column()可以识别ua是可选类型吗?

No, you can't. 不,你不能。 Right now the only data you can read from the decorator is the type of the property, name of the property, and class where this property is (even this is achieved throw the reflect-metadata ). 现在,您可以从装饰器读取的唯一数据是属性的类型,属性的名称以及该属性所在的类(即使通过抛出reflect-metadata )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM