-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Eslint-plugin: Add method-signature-style TypeScript lint rule #62718
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: 0 B Total Size: 1.76 MB ℹ️ View Unchanged
|
42c407c
to
e8d9a20
Compare
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.
👍 Really weird though :P
This subtle change can dramatically change the type system's behavior. ```ts type Rec = Record<string, unknown>; interface Post extends Rec { status: string; } interface Base<T> { isEligibleMethod(item: T): boolean; isEligibleFunc: (item: T) => boolean; } const base: Base<Rec> = { // Using the "method" type syntax above weakens the type checking. // This is not a type error!!! isEligibleMethod: (item: Post) => item.status.startsWith('eli:'), // This is a type error as expected. isEligibleFunc: (item: Post) => item.status.startsWith('foo'), } ``` See https://typescript-eslint.io/rules/method-signature-style
e8d9a20
to
853ee41
Compare
…ress#62718) This subtle different can influence the type system's behavior in dramatic and surprising ways. See https://typescript-eslint.io/rules/method-signature-style for details. --- Co-authored-by: sirreal <jonsurrell@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
What?
Add the method-signature-style to the recommended TypeScript rule set.
Why?
This subtle change is not obvious but can dramatically weaken (or strengthen) the type system.
See https://typescript-eslint.io/rules/method-signature-style
This was discovered in #62647 (comment) with the help of @jsnajdr.
How?
Add and enable the rule in the recommended TypeScript rule set.
Testing Instructions
CI passes.