Issue
I want to set current function to null loop in typescript, this is my code looks like:
export function noop() {}
export function removeFirstMouseUp() {
removeFirstMouseUp = noop;
}
but the compiler told me this error:
TS2630: Cannot assign to 'removeFirstMouseUp' because it is a function.
assign a function to another function, it seems no problem. why the typescript compiler shows this error? what did I do to fix this problem?
Solution
Instead of defining removeFirstMouseUp
as a function declaration, rewrite it as a function definition:
export function noop() {}
export let removeFirstMouseUp = function() {
removeFirstMouseUp = noop;
}
From ESLint's no-func-assign page:
JavaScript functions can be written as a FunctionDeclaration function foo() { ... } or as a FunctionExpression var foo = function() { ... };. While a JavaScript interpreter might tolerate it, overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue.
ESLint and TypeScript are different, however, in this case the error messages are referring to the same thing.
Answered By - kenset
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.