Skip to content

Generic type param used as generic type constraint causes variance issues? #33561

Closed
@AnyhowStep

Description

@AnyhowStep

TypeScript Version: 3.5.1, 3.6.3, Nightly

Search Terms:

generic type parameter, generic type constraint, variance

Code

declare const x0 : <InT extends boolean|null>(arg : InT) => boolean;
//Expected: Error
//Actual  : Error
const x1 : <InT extends string>(arg : InT) => boolean = x0;

type Y<In, Out> = <InT extends In>(arg : InT) => Out;
declare const y0 : Y<boolean|null, boolean>;
//Expected: Error
//Actual  : OK
const y1 : Y<string, boolean> = y0;

Expected behavior:

y1 = y0 assignment should fail

Actual behavior:

y1 = y0 assignment passes

Playground Link:

3.5.1 Playground

3.6.3 Playground

Nightly Playground

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions