Getting a modified type from a class marked by decorator

53 Views Asked by At

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,
}
1

There are 1 best solutions below

0
Matthieu Riegler On BEST ANSWER

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.