New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impossible to define static 'length' function on class #9215
Conversation
checkNameOfStaticMethodOrPropertyInClass(node); | ||
} | ||
|
||
function checkNameOfStaticMethodOrPropertyInClass(node: ClassElement) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider this as grammar check -> like call it checkGrammarStaticPropertyName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do this in a more generic fashion and not hard code the names. we should use the Function
type and make sure we are not redefining any of the properties there. possibly readonly
ones only. this way users can add/remove some of these checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR @plantain-00 ! Additional comment is that I believe there need to be distinction between static property and static method declaration when users target ES5, ES6
EDIT: i make an inline edit, as my original comment is incorrect |
Regardless of the previous comment, @vladima points out that this rule should be extended to "ComputedProperty" with string literal of the value: length, name, arguments, caller Could you add additional tests for such case? |
@yuit class C {
static caller = { // error: caller
[name]: "abc", // error: name
[length]: 1, // error: length
};
} |
@plantain-00 almost but using string literal instead. In your example, it is an expression class C {
static caller = { // error: caller
["name"]: "abc", // error: name
["length"]: 1, // error: length
};
} |
6d94928
to
12e2118
Compare
any comments? |
@yuit sorry I missed my ping. Confirming that this change is correct, length, arguments, caller, and name are all valid static method names in ES6. |
!!! error TS2690: 'caller' is not allowed to be used as a name of a static property or method in a class. | ||
static foo = { | ||
["length"]: 1, | ||
~~~~~~~~~~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a comment(above) from yuit:
this rule should be extended to "ComputedProperty" with string literal of the value: length, name, arguments, caller
dceba92
to
f8366b6
Compare
any comments? |
Fixed by #12065 |
Fixes #442