Allow assignment to readonly parameter property within the constructor#8712
Conversation
|
Hi @Andy-MS, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
|
👍 |
| const func = getContainingFunction(expr); | ||
| return !(func && func.kind === SyntaxKind.Constructor && func.parent === symbol.valueDeclaration.parent); | ||
| return !isInConstructor(getContainingFunction(expr)); | ||
| function isInConstructor(func: FunctionLikeDeclaration) { |
There was a problem hiding this comment.
I think this shouldn't be nested. @vladima there is some performance hint when nesting the function like this if I recall correctly?
There was a problem hiding this comment.
I think this would read better closer to the old style -- just const func = getContainingFunction(expr); if (!func) ....
The trailing nested function strikes me as a Haskell-ism.
There was a problem hiding this comment.
nit: could you renamed the function -> the current name imply me that you are checking if func is in constructor. But my understanding is that you are checking if symbol is inside the constructor of the class that defines it..isSymbolReferredInsideOriginalConstructor or something like that. Others may have better idea for name 😅
|
👍 |
|
what happen in this case? class A {
constructor(readonly x: number) {
this.x = 7;
}
}
class B extends A {
constructor(readonly x: number) {
this.x = 10;
}
}Otherwise lgtm 🍰 |
|
👍 |
Fixes #8689