Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:typescript-code-style/no-return-assign
Language: TypeScript
Severity: Notice
Category: Error Prone
Description
JavaScript allows return statements to do assignment operations. Because it is hard to differentiate between an assignment and a comparison when written as part of the return statement, avoid using return statements.
Non-Compliant Code Examples
functionx() {returnresult=a*b;};functionx() {return(result)=(a*b);};functionx() {returnresult=a*b;};functionx() {return(result)=(a*b);};()=>{returnresult=a*b;};()=>result=a*b;functionx() {returnresult=a*b;};// Allow parens option not supported
// function x() { return (result = a * b); };
// function x() { return result || (result = a * b); };
functionfoo(){returna=b}functiondoSomething() {returnfoo=bar&&foo>0;}functiondoSomething() {returnfoo=function(){return(bar=bar1)}}functiondoSomething() {returnfoo=()=>a}functiondoSomething() {return()=>a=()=>b}functionfoo(a){returnfunctionbar(b){returna=b}}constfoo=(a)=>(b)=>a=b;