Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AnyhowStep opened this issue Sep 23, 2019 · 3 comments
Closed

Comments

@AnyhowStep
Copy link
Contributor

AnyhowStep commented Sep 23, 2019

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:

@AnyhowStep
Copy link
Contributor Author

Seems like the type inference is OK, though,

/**
 * type test0 = [boolean | null, boolean]
 */
type test0 = typeof y0 extends Y<infer In, infer Out> ?
    [In, Out] :
    never;

/**
 * type test1 = [string, boolean]
 */
type test1 = typeof y1 extends Y<infer In, infer Out> ?
    [In, Out] :
    never;

3.5.1 Playground

@jack-williams
Copy link
Collaborator

Duplicate of #31006 and fixed by #31029.

@AnyhowStep
Copy link
Contributor Author

AnyhowStep commented Sep 23, 2019

It's not in the nightly builds?

[Edit]
Oh, not merged yet.

I guess I'll close this and monitor that PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants