TS1308: 'await' has no effect on the type of this expression
What’s happening?
Section titled “What’s happening?”This error occurs when you use await on a value that is not a Promise.
TypeScript detects that the await keyword has no effect because the value is already synchronous.
Reproduction
Section titled “Reproduction”function getName(): string { return "Alice";}
async function greet() { const name = await getName(); // ❌ 'await' has no effect on the type of this expression console.log(name);}getName() returns a plain string, not a Promise<string>, so await is unnecessary.
Why does TypeScript complain?
Section titled “Why does TypeScript complain?”TypeScript analyzes the return type:
Promise<T>→awaitis needed ✅T(non-Promise) →awaithas no effect ❌
Using await on non-Promise values suggests a misunderstanding of async code.
Solutions
Section titled “Solutions”Option 1: Remove await (recommended)
Section titled “Option 1: Remove await (recommended)”async function greet() { const name = getName(); // ✅ No await needed console.log(name);}When to use:
- ✅ The function returns a synchronous value
- ✅ Simplest and clearest solution
Option 2: Make the function async
Section titled “Option 2: Make the function async”async function getName(): Promise<string> { return "Alice"; // Automatically wrapped in Promise}
async function greet() { const name = await getName(); // ✅ Now await is needed console.log(name);}When to use:
- ✅ The function will eventually need to be async (e.g., fetching data)
- ✅ You want a consistent async API
Option 3: Return a Promise explicitly
Section titled “Option 3: Return a Promise explicitly”function getName(): Promise<string> { return Promise.resolve("Alice");}
async function greet() { const name = await getName(); // ✅ console.log(name);}When to use:
- ✅ Wrapping synchronous code to match an async interface
Common scenarios
Section titled “Common scenarios”Awaiting synchronous array methods
Section titled “Awaiting synchronous array methods”const users = ["Alice", "Bob"];const first = await users[0];// ❌ 'await' has no effect
// ✅ Fix: Remove awaitconst first = users[0];Awaiting a value instead of a Promise-returning function
Section titled “Awaiting a value instead of a Promise-returning function”const result = await fetchData;// ❌ If fetchData is a Promise, not a function
// ✅ Fix: Call the functionconst result = await fetchData();Mixed sync/async code
Section titled “Mixed sync/async code”async function processData(data: string) { const parsed = await JSON.parse(data); // ❌ JSON.parse is synchronous
// ✅ Fix: const parsed = JSON.parse(data); const validated = await validateData(parsed); // This actually needs await}Key takeaways
Section titled “Key takeaways”- Only use
awaitwith Promises - TypeScript’s error helps you avoid unnecessary
await - If you need async behavior, make the function return a Promise
- Remove
awaitfrom synchronous operations