Support constructor parameter annotations to improve the code readability #374
Replies: 1 comment 1 reply
-
It's really not about whether it is possible or not. There's a bit of a story 😅 To get into explaining this, I'd like to start with the
class Foo {
foo: string;
bar: string;
}
console.log(new Foo()); // Foo {} As you can see here, a new instance of class Foo {
constructor(
public foo?: string,
public bar?: string
) {}
}
console.log(new Foo()); // Foo { foo: undefined, bar: undefined } Great! Now a new instance of Also, your proposal would limit this as well #319 (though this has not been implemented yet 🥲). That said, I think a new |
Beta Was this translation helpful? Give feedback.
-
Hello! I am not sure if this is even possible, but I think it is worth mentioning it for the future.
I have written my data classes by taking advantage of TS syntax like this:
Now I have to add the
@AutoMap
annotation to the class and they don't work if I put them on top of the constructor parameters, like this:Because this is not supported (maybe JS/TS itself won't support this syntax) I have to break down this code into constructor+property, which triplicates the length of my code, ending up in something like this:
Is there any better, less verbose way, to do what I am doing here?! Do yo plan to support such syntax (if even possible, of course)?
Congrats on the great work on AutoMapper! 🥇
Beta Was this translation helpful? Give feedback.
All reactions