Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model annotations on constructor parameters #2

Open
haraldk opened this issue Sep 24, 2019 · 0 comments
Open

Model annotations on constructor parameters #2

haraldk opened this issue Sep 24, 2019 · 0 comments

Comments

@haraldk
Copy link

haraldk commented Sep 24, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant