Skip to content

Model annotations on constructor parameters #2

Description

@haraldk

Thanks for providing a useful library!

I have one problem that I can't seem to solve, how is one expected to annotate member fields declared in a constructor?

Example:

export class Price {
  constructor(private value: number, private currency: Currency) {
  }

 // ...
}

I would think this could be done using something like this:

export class Price {
  constructor(private value: number, @dataType(Currency) @converters({
    'string': (currency: any) => Currency[currency as string]
  }) private currency: Currency) {
  }

 // ...
}

export enum Currency {
  USD,
  EUR
}

But it does not work (ie. nothing happens at all, no error message, no exception, but also no conversion, the structure seems to be just left as the original JSON input).

PS: I'm mainly a Java developer, and not very experienced with TypeScript (or JavaScript), so I might be missing something obvious here...

Best regards,

--
Harald K

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions