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

Weak generic constraint check #42145

Closed
awerlogus opened this issue Dec 29, 2020 · 6 comments
Closed

Weak generic constraint check #42145

awerlogus opened this issue Dec 29, 2020 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@awerlogus
Copy link

TypeScript Version: 4.2.0-dev.20201222

Search Terms: generic constraint check

Code

type Emit<E extends string> = { emit<T extends E>(event: T): void }

type EmitAB = Emit<'a' | 'b'>
type EmitCD = Emit<'c' | 'd'>

declare const emitAB: EmitAB

// Actually: no error
// Expected: EmitAB is not assignable to EmitCD
const emitCD: EmitCD = emitAB

Expected behavior:
EmitAB is not assignable to EmitCD

Actual behavior:
No error

@andrewbranch
Copy link
Member

Note that neither the method nor the union types are necessary to repro:

type Emit<E extends number> = <T extends E>(event: T) => T

declare let emit0: Emit<0>;
declare let emit1: Emit<1>;

emit0 = emit1;
emit1 = emit0;

@andrewbranch andrewbranch added the Bug A bug in TypeScript label Dec 29, 2020
@andrewbranch andrewbranch added this to the Backlog milestone Dec 29, 2020
@DanielRosenwasser
Copy link
Member

I think that this is a duplicate of #31006 - @ahejlsberg can you confirm?

@DanielRosenwasser
Copy link
Member

Relevant design meeting might be #31132.

@awerlogus
Copy link
Author

It's hard to imagine that accessing some type in type level closure may cause so many problems

@DanielRosenwasser DanielRosenwasser added Duplicate An existing issue was already created and removed Bug A bug in TypeScript labels Jan 26, 2021
@DanielRosenwasser DanielRosenwasser removed this from the Backlog milestone Jan 26, 2021
@DanielRosenwasser
Copy link
Member

I'm going to assume this is a duplicate.

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants