Bug Report
🔎 Search Terms
Generic inference, destructuring, binding patterns
🕗 Version & Regression Information
Exists in 4.3.5
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics
⏯ Playground Link
Playground link with relevant code
💻 Code
declare function genericFunc<T>(): T;
const { bar } = genericFunc();
// `bar` is `any` here.
🙁 Actual behavior
bar is any and T is inferred to be { bar: any }.
🙂 Expected behavior
The inferred type of T should be unknown and there should be an error from trying to destructure it.
(Or, T could still be inferred as { bar: any } but then noImplicitAny should trigger an error. This seems at a glance less desirable to me than the former, but I don't know enough how generic inference works to make a more informed recommendation. Anyways, some sort of error no matter how it happens is what would be ideal!)
Notes: see #43371 (comment) for the original context.
Bug Report
🔎 Search Terms
Generic inference, destructuring, binding patterns
🕗 Version & Regression Information
Exists in 4.3.5
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
barisanyandTis inferred to be{ bar: any }.🙂 Expected behavior
The inferred type of
Tshould beunknownand there should be an error from trying to destructure it.(Or,
Tcould still be inferred as{ bar: any }but thennoImplicitAnyshould trigger an error. This seems at a glance less desirable to me than the former, but I don't know enough how generic inference works to make a more informed recommendation. Anyways, some sort of error no matter how it happens is what would be ideal!)Notes: see #43371 (comment) for the original context.