coderaiser / putout

🐊 Pluggable and configurable JavaScript Linter, code transformer and formatter, drop-in ESLint superpower replacement 💪 with built-in support for js, jsx, typescript, flow, markdown, yaml and json. Write declarative codemods in a simplest possible way 😏
https://putout.cloudcmd.io/
MIT License
698 stars 40 forks source link

[printer] Removes any `declare` of class properties. #175

Closed ElPrudi closed 1 year ago

ElPrudi commented 1 year ago

If you want to do more complex polymorphism in TypeScript, there's a problem when it comes to instance properties: you can't change their inherited type. But if the subclasses fully manage this type and it mostly completely overlaps with the type of the properties in the parent class, TypeScript lets you declare the type again:

export default class SuperTest extends Test {
    protected declare title: string[] // change the type of title from string to string[], because why not?
}

After transformation, it looks like this:

export default class SuperTest extends Test {
    protected title: string[]  // Error! Can not redeclare an inherited property!
}
coderaiser commented 1 year ago

TypeScript has so many abilities 😀... Just fixed 🎈! Is it works for you?

ElPrudi commented 1 year ago

It doesn't try to change it anymore. Thank you very much :)