Open kirkwaiblinger opened 2 days ago
It's worth noting that this is an error in flow. It doesn't error for the reasons kirk mentioned though and instead errors because Flow treats all methods as readonly always to prevent unsafe / hard to analyse changes to classes like this.
🔎 Search Terms
own property, shadow, prototype, method, field, inheritance
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241201#code/MYGwhgzhAEBiD29oG8BQ0PWPAdhALgE4Cuw+8hAFAJQrqYP4AWAlhAHQAOh85+AnpwCmAWSHN4AE2gBeaDVkA+Og1WZseeCCHsQ8AOaUA5BCZhJ8AO4xuvXoKHQAtuKZSj1ANz01AXx-Q-gy2fA5iEpIKaGoYGhBaOnqGRi4R0LjQIfbCHt4M-r5AA
💻 Code
🙁 Actual behavior
no error
🙂 Expected behavior
error - something like "Type 'Foo' has no instance property named 'prototypeMethod'. If you meant to reassign the method 'prototypeMethod', it must be a function-valued instance property instead of a prototype method.".
I expect an error here because the code is effectively equivalent to
which is a TS error (see https://github.com/microsoft/TypeScript/issues/13141).
Furthermore, it breaks error reporting in subclasses. The following code correctly reports a TS error due to the extended class not being able to override an instance property with a method: (playground)
However, this does not (playground)
Additional information about the issue
inspired by https://github.com/typescript-eslint/typescript-eslint/issues/10427
cc @miguel-leon