Home > database >  Getting a modified type from a class marked by decorator
Getting a modified type from a class marked by decorator

Time:07-11

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

CodePudding user response:

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.

  • Related