Closed
Description
π Search Terms
- missing await in conditional
- await
- conditional
π Version & Regression Information
Since 4.3.0-dev
β― Playground Link
Playground link with relevant code
π» Code
declare const cache: Record<string, Promise<string>>
declare const fetchThing: (id: string) => Promise<string>
const getCachedThing1 = (id: string) => {
let thing = cache[id]
return !thing // not an error, if the error in getCachedThing3 is valid then why this isn't an error?
? (cache[id] = fetchThing(id))
: thing
}
const getCachedThing2 = (id: string) => {
let thing = cache[id]
return thing ?? (cache[id] = fetchThing(id)) // not an error
}
const getCachedThing3 = (id: string) => {
let thing = cache[id]
return thing // error (2801), but it should't be, getCachedThing3 isn't async function
? thing
: (cache[id] = fetchThing(id))
}
After applying quick fix to getChachedThing3
error:
const getCachedThing3 = (id: string) => {
let thing = cache[id]
return await thing // error (2801), but it should't be, getCachedThing3 isn't async function
// error (2801), but it should't be, getCachedThing3 isn't async function
? thing
: (cache[id] = fetchThing(id))
}
Quick fixed code is invalid (await
is added to non-async function). Also, comment gets duplicated.
π Actual behavior
- Missing await in conditional errors are inconsistent
- Missing await in conditional errors get reported in non-async functions
- Quick fixing the error in non-async function produces invalid results
π Expected behavior
- Missing await in conditional errors to be consistent
- Missing await in conditional errors to NOT be reported in non-async functions
- No quick fix suggestion in non-async function
As a sidenote, I think the "missing await in conditional error" feature should be under a flag
- It is wildly inconsistent
- This is a job for linters
- Objects are thruthy, so let them be thruthy :)
- This feature breaks existing code