Skip to content

Infer bottom type for type argument when passing empty array #8878

Closed
@ivogabe

Description

@ivogabe

I think the bottom type, never, could be used for this case: when passing an empty array to an argument of type T[], where T is a type argument.

@ahejlsberg What do you think?

TypeScript Version:

1.7.5 / 1.8.0-beta / nightly (1.9.0-dev.20160528-1.0)

Code

function a<T>(xs: T[]) {
    return xs;
}
const x = a([]);
function b<T extends Node>(xs: T[]) {
    return xs;
}
const y = b([]);

Expected behavior:
Type of x would be never[], y would be Node[]

Actual behavior:
Type of x is any[], y is any[].

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions