You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constfoo=<T>(fn: ()=>T): T=>fn();foo(()=>y);// no error for reference to y here, but there will be a runtime ReferenceErrorconsty: string=(()=>y)();// ts will error on the reference to y here inside IIFE
🙁 Actual behavior
TS isn't catching references to variables (let, const or var) before they are defined when used as a parameter to another function call.
🙂 Expected behavior
In the example above, I'd expect it to error on the use of y in the function argument to foo.
Additional information about the issue
I discovered the issue while writing a React component with useMemo and did a silly like this:
const MyComponent = () => {
const value: string = useMemo(() => value, []); // no ts error but there is a ReferenceError thrown at runtime
return null;
}
The text was updated successfully, but these errors were encountered:
🔎 Search Terms
"reference error", "Block-scoped variable used before its declaration", "ts(2448)", "Variable is used before being assigned", "ts(2454)"
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?jsx=0#code/MYewdgzgLgBAZiEMC8MA8AVAfACjmALhhwEoUsYMSiNz4xSBuAKGYRB1LoE8SXnQkWNyLQATgEswAcxTEuyCryZA
💻 Code
🙁 Actual behavior
TS isn't catching references to variables (let, const or var) before they are defined when used as a parameter to another function call.
🙂 Expected behavior
In the example above, I'd expect it to error on the use of
y
in the function argument tofoo
.Additional information about the issue
I discovered the issue while writing a React component with
useMemo
and did a silly like this:The text was updated successfully, but these errors were encountered: