Use typescript to dynamically set class property in constructor

0 votes

I am trying create a typescript class MyClass with instance properties set dynamically in the constructor:

const myInstance = new MyClass(({
  someField: 'foo'
}))

myInstance.someField // typescript should show this as type string

How can I use typescript to create MyClass to show someField as a string property of myInstance?

Can I use generics? Is it at all possible?

Aug 3, 2022 in TypeSript by Elton
• 400 points

edited Mar 4 6 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP