Description
Bug Report
🔎 Search Terms
array union types type inference noImplicitAny disabled
🕗 Version & Regression Information
This changed between versions 4.2.3
and 4.3.5
, as before 4.3.5
, type inference for the 2nd case inferred any
regardless of if noImplicitAny
was enabled. After 4.3.5
, the expected inference happens when noImplicitAny
is enabled, but behaves as it did before 4.3.5
when noImplicitAny
is not enabled.
⏯ Playground Link
Playground link with relevant code
💻 Code
// `item` and `key` are both typed as expected (`string | number` and `number` respectively)
const array1: Array<string | number> = [];
const mapped1 = array1.map((item, key) => [item, key])
// `item` and `key` are both typed as `any`
const array2: Array<string> | Array<number> = [];
const mapped2 = array2.map((item, key) => [item, key])
🙁 Actual behavior
When noImplicitAny
is not enabled in the TS config, inferred types are impacted (inferred as any
in the above case).
🙂 Expected behavior
noImplicitAny
shouldn't impact inferred types, or if this is expected behaviour as having this option enabled allows for better heuristics to work, then I think having it documented that this settings isn't essentially just a "lint rule" might be a good idea.