Skip to content

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

Description

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.

Anders Hejlsberg (@ahejlsberg) What do you think?

TypeScript Version:

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

Code

functiona<T>(xs: T[]){returnxs;}constx=a([]);functionb<TextendsNode>(xs: T[]){returnxs;}consty=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

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions