简体   繁体   English

从装饰器标记的类中获取修改后的类型

[英]Getting a modified type from a class marked by decorator

I have a class defined like:我有一个定义如下的类:

class Person {
    @OneToOne()
    pet: Animal;
}

Is there a way to get a modified type which looks like this?有没有办法获得看起来像这样的修改类型? (Adding {propertyKey}Id: string to properties by marking it with a decorator) (将{propertyKey}Id: string添加到属性中,通过装饰器对其进行标记)

// Using generics
type ModifiedPerson = SomeGeneric<Person>

// Or maybe using functions?
type ModifiedPerson = typeof someFunc(Person);

// Equivalent as:
type ModifiedPerson = {
    pet: Animal,
    petId: string,
}

What you are asking is not properly possible with typescript today.你问的问题今天用打字稿是不可能的。 There is a pending issue open since 2015 on GitHub .自 2015 年以来在 GitHub 上存在一个未决问题

@Decorators have no effect on type. @Decorators对类型没有影响。

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

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