Search code examples
javascripttypescriptdestructuring

Typescript - making property as public in destructuring constructors


Is there a way to make property as public in Destructuring for constructors?

Supposed to be there are many properties in Person Class.

Instead of

// to create a Person. new Person('')
class Person {
    constructor(public name: string) {

    }
}

I want to use destructuring to pass object as constructor parameter and make properties as public.

//new Person({name: ''})
class Person {
    constructor({
        public name: string //Is there a workaround here?
    }) {

    }
}

Is there a workaround here?


Solution

  • No currently that is not possible but there is an active discussion around this on this GitHub issue