2016-09-10 2 views

답변

1

ESlint는 이것을 잡지 않지만, avoid the Promise constructor 모두합시다!

return (condition ? asyncMethod : Promise.resolve()).then(data => syncMethod()); 

은 반환이 일치하지 않습니다 누락 된 경우 무엇입니까?

약속 생성자에있는 if 블록의 내용이 return이 아닙니다. 또는 else 블록에서 resolve() 통화 결과를 return에 가져 오면 안됩니다.

1

if 블록 내에서 값을 반환하지 않는 :이 경우는 false 함수가, 사실 undefinedcondition 경우 반환하지만, 해결 함수의 결과를 반환하는 것을 의미합니다

if (condition) { 
    asyncMethod.then(data => { 
    return resolve(syncMethod()); 
    }, err => reject(err)); 
} 

.

+0

오, 그게 말이 되네, 어떻게 고칠 수 있겠 니? – uzyn

+0

확실히 반환 값을 추가하면됩니다.이 값은 여러분이 사용하고있는 것에 따라 다르지만, 단지 return asyncMethod.then (data => {return resolve (syncMethod());}, err = > 거부 (오류)); – Matt