Skip to content
← Back to rules

promise/prefer-await-to-then 스타일

작동 방식

프로미스 값 읽기 시 then()/catch()/finally() 대신 await 사용 권장

왜 나쁜가요?

비동기/대기(Async/await) 문법은 더 가독성이 뛰어납니다.

예시

이 규칙에 잘못된 코드 예시:

javascript
function foo() {
  hey.then((x) => {});
}

이 규칙에 올바른 코드 예시:

javascript
async function hi() {
  await thing();
}

엄격 모드 예시

{ strict: true } 설정 시 잘못된 코드 예시:

javascript
async function hi() {
  await thing().then((x) => {});
}

구성

이 규칙은 다음 속성을 가진 구성 객체를 수용합니다.

strict

type: boolean

기본값: false

true로 설정 시, await 또는 yield 표현식 이후에도 규칙을 강제 적용합니다.

사용 방법

이 규칙을 활성화하려면 구성 파일 또는 명령줄 인터페이스에서 다음을 사용할 수 있습니다:

json
{
  "plugins": ["promise"],
  "rules": {
    "promise/prefer-await-to-then": "error"
  }
}
bash
oxlint --deny promise/prefer-await-to-then --promise-plugin

참고 자료