-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed as not planned
Closed as not planned
Copy link
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
🔎 Search Terms
uninitialized variable, lexical scoping, circular reference
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about uninitialized variables
- I encountered this error on my company's TypeScript version (5.3.3), and reproduced it on Nightly in the playground.
- I encountered this issue, though it seems to be filled with people asking for fewer errors when their code has circular references😅 T implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer #35546
⏯ Playground Link
💻 Code
// In the real code, all of these functions are async and return promises;
// I just made everything synchronous here to minimize the test case
// The real version of this function does caching stuff
function fetchCachedValues<V>(fetchOnCacheMiss: () => V): V {
return fetchOnCacheMiss();
}
const getCoolnessUsingCache = (): boolean => {
const isCool = fetchCachedValues((): boolean => {
// This typechecks just fine, even though `isCool` is not initialized here!
return isCool;
});
return isCool;
}
// Runtime error: Cannot access 'isCool' before initialization
getCoolnessUsingCache();🙁 Actual behavior
TypeScript reports no errors. Running the code gives a runtime error: Cannot access 'isCool' before initialization
🙂 Expected behavior
I think TypeScript should report an error! Possibly Block-scoped variable 'isCool' used before its declaration.(2448)
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created