score:2
the rule is about consistent return: https://eslint.org/docs/rules/consistent-return
a confusing aspect of javascript is that a function returns undefined if any of the following are true:
- it does not execute a return statement before it exits
- it executes return which does not specify a value explicitly
- it executes return undefined
- it executes return void followed by an expression (for example, a function call)
- it executes return followed by any other expression which evaluates to undefined
if any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function.
so what you need you can do to get rid of the message is:
- explicitly return something in the
try
block (return undefined
if you will) - stop returning in the
catch
block - disable the rule for that function
score:0
the correct syntax is:
function getsizefromobjecturl(dataurl: string): promise<any> {
return new promise((resolve, reject) => {
try {
const img = new image();
img.onload = () => {
const ratio = math.min(300.0 / img.width, 300.0 / img.height);
resolve({
height: img.height * ratio,
width: img.width * ratio
});
};
img.src = dataurl;
} catch (exception) {
reject(exception);
}
});
}
it's actually complaining about the return before resolve / reject not after the arrow. cuz the resolve and reject functions are voids
for the error unexpected lexical declaration in case block.
, use the case like this :
case x: {
// your code goes here
}
instead of:
case x:
// your code
score:0
i removed return before promise resolve/reject. this works -
function getsizefromobjecturl(dataurl: string): promise<any> {
return new promise((resolve, reject) => {
try {
const img = new image();
img.onload = () => {
const ratio = math.min(300.0 / img.width, 300.0 / img.height);
resolve({
height: img.height * ratio,
width: img.width * ratio
});
};
img.src = dataurl;
} catch (exception) {
reject(exception);
}
});
}
Source: stackoverflow.com
Related Query
- Expected to return a value at the end of arrow function on reactjs how to fix this error?
- How to fix expected to return a value at the end of arrow function warning in react js?
- How should I fix "Expected to return a value at the end of arrow function."?
- How to fix linter expected to return a value at the end of react function component?
- How do I fix "Expected to return a value at the end of arrow function" warning?
- Expected to return a value at the end of arrow function with if statement
- Expected to return a value at the end of arrow function array-callback-return on filter function
- react warning Expected to return a value at the end of arrow function array-callback-return
- Should I return true to clear .map() expects a value to be returned at the end of arrow function warning?
- React JS - Expected to return a value at the end of arrow function ES lint Error
- 118:51: Expected to return a value at the end of arrow function array-callback-return
- warning Expected to return a value at the end of arrow function
- Expected to return a value at the end of arrow function in react
- How fix this warrning warning Array.prototype.map() expects a return value from arrow function array-callback-return?
- Expected to return a value at the end of this function array-callback-return in React JS
- How to fix "Array.prototype.filter() expects a value to be returned at the end of arrow function"
- How to tell TS explicitly that the return value of a function will be expected to be of a certain type?
- How fix warning "Expected to return a value in arrow function array-callback-return"
- How to fix "Expected to return a value in arrow function array-callback-return"?
- How to fix "Expected to return a value in arrow function" with reactjs?
- Async arrow function expected no return value
- How to fix 'Expected the return value to be a 31-bit integer' error react hooks
- How do I fix a React TypeScript error with the return value of useHotkeys hook not matching the type of the div element ref prop
- Array.prototype.filter() expects a value to be returned at the end of arrow function
- How to return 2 function calls in the arrow function at once?
- How to get the return value of a async function that returns a promise
- How to store the return value of a function inside a variable in reactJS
- How to pass the return value of a function as a property to a react component
- How to get the return value of parent function to child component in react (Using props)
- Array.prototype.map() expects a value to be returned at the end of arrow function
More Query from same tag
- Type 'Element' is missing the following properties from type 'SVGSVGElement'
- Hover over div/image to fade out image and have text fade in, but hovering over text removes fade out of image. How to prevent?
- postman: You need to enable JavaScript to run this app
- ReactJS and Laravel, nested route is not working. It bring me to the same page
- Different height columns in Material UI need fixing
- How does nested function in an event handler receive the event object?
- React.js component life cycle, state behavior and asynchronous nature of JavaScript
- 'dispatch' is not defined
- Firebase signInWithGoogle() wants me to fill the email and password fields?
- How to deploy Next.js app without Node.js server?
- How to make a permutation code more concise?
- Is there a react component event for when url query string parameters change?
- How do I clear/reset input data in a react.js form?
- Invariant Violation: Could not find "store" in the context of "Connect(AddTodo)".when executing npm test
- SetTimeout runs twice, only if the component is reconstructed
- How to handle popup state in redux?
- Validate inputs in a calculator - React
- How to change proxy of client server
- Using base64 Encoding When Passing Data from Node to React to Construct PDF
- React Slick dots doesnt show
- why is first letter dead in react-hook-form input
- Override shouldcomponentupdate with HOC
- React redux pass state down to children
- How to convert MongoDB Buffer to Image in React/Node/Express
- How to include state/props in useEffect without it becoming a trigger?
- What's the difference between mapDispatchToProps and {action}
- How to update the display properly in React?
- How can I change parent state in two children components using Hooks in React?
- Primary and secondary font with Chakra UI
- module.exports and ... what does it refer to