-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
chore: useMemoizedFn: declare this explicitly #1464
Conversation
|
@@ -17,8 +17,7 @@ function useMemoizedFn<T extends noop>(fn: T) { | |||
|
|||
const memoizedFn = useRef<T>(); | |||
if (!memoizedFn.current) { | |||
memoizedFn.current = function (...args) { | |||
// eslint-disable-next-line @typescript-eslint/no-invalid-this | |||
memoizedFn.current = function (this, ...args) { |
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.
这是用户在调用函数的时候,需要给第一个参数传递 this 吗?
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.
不需要,这里的 this 仅声明,调用函数只需要传递 args,编译成 js 后就没有 this 了
https://www.typescriptlang.org/docs/handbook/2/functions.html#declaring-this-in-a-function
可以在线预览一下编译后的结果
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 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.
不需要,这里的 this 仅声明,调用函数只需要传递 args,编译成 js 后就没有 this 了
https://www.typescriptlang.org/docs/handbook/2/functions.html#declaring-this-in-a-function 可以在线预览一下编译后的结果
原来如此~
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.
LGTM
错了,不是这个 PR 引起的。 是另外一个 #1470 |
抱歉,因为我的考虑不周导致了新的问题😵。 |
[English Template / 英文模板]
🤔 这个变动的性质是?
💡 需求背景和解决方案
显式地声明 this,无需强制关闭 eslint 了。
📝 更新日志
☑️ 请求合并前的自查清单