Skip to content

Bad type inference under --strictFunctionTypes #19576

@gcnew

Description

@gcnew

TypeScript Version: 2.7.0-dev.20171029

Code

type Comparator<T> = (x: T, y: T) => number;

interface LinkedList<T> {
    comparator: Comparator<T>,
    nodes: Node<T>
}

type Node<T> = { value: T, next: Node<T> } | null

declare function compareNumbers(x: number, y: number): number;
declare function mkList<T>(items: T[], comparator: Comparator<T>): LinkedList<T>;

const list: LinkedList<number> = mkList([], compareNumbers); // `T` inferred as `never`,
                                                             //     should   be `number`

Actual behavior:

The implicit evolving never[] type of the array literal is taking precedence, leading to unexpected results.

Metadata

Metadata

Assignees

Labels

FixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions