Skip to content

Mixing tuple & generics #1011

Closed
Closed
@srenault

Description

@srenault

Hi, don't understand why this code doesn't compile:

function f<T>(value: [string, T]): T {
  return value[1];
}
var h: boolean = f(["string", true]);
error TS2323: Type 'string | boolean' is not assignable to type 'boolean'.
Type 'string' is not assignable to type 'boolean'.

Someone can help me ?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptSpecIssues related to the TypeScript language specification

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions