-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsSuggestionAn idea for TypeScriptAn idea for TypeScript