简体   繁体   中英

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)

// 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 .

@Decorators have no effect on type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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