타입스크립트 에러 사전await 안 붙였다고 경고가 떠요“promise 를 안 기다림”
메뉴판 › 타입스크립트 에러 사전 › async·Promise › async 함수 결과가 Promise라고 떠요
error TS2322: Type 'Promise<number>' is not assignable to type 'number'.
전
async function g(): Promise<number> { return 1; }
function use() {
const n: number = g(); // await 빠짐
}후
async function g(): Promise<number> { return 1; }
async function use() {
const n: number = await g();
}왜 이렇게 되나
- async 함수를 await 없이 불러서, 값이 아니라 Promise 가 나온다
됐는지 보는 법
await가 붙고 실제 값이 나오면 성공.
같은 묶음 · async·Promise
타입스크립트 에러 사전 · async·Promise