Bug Report
π Search Terms
array tuple contextual type inference union implicit any
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
Playground link with relevant code
π» Code
declare function test(
arg: Record<string, (arg: string) => void> | Array<(arg: number) => void>
): void;
test([
(arg) => {
arg; // actual: any; expected: number
},
]);
π Actual behavior
The contextual type for array element is sourcing the information from the string indexer of the Record type. This makes the contextual type of this function to be ((arg: string) => void) | ((arg: number) => void). The contravariant position of arg makes its type reduce to never (since it's string & number) and prevents the expected contextual type to be provided.
π Expected behavior
I'd expect this contextual type to only be sourced from the Array member
Bug Report
π Search Terms
array tuple contextual type inference union implicit any
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The contextual type for array element is sourcing the information from the string indexer of the
Recordtype. This makes the contextual type of this function to be((arg: string) => void) | ((arg: number) => void). The contravariant position ofargmakes its type reduce tonever(since it'sstring & number) and prevents the expected contextual type to be provided.π Expected behavior
I'd expect this contextual type to only be sourced from the
Arraymember