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

Upper-bounded generic type relaxes bigint restriction #49907

Closed
theonlypwner opened this issue Jul 14, 2022 · 0 comments Β· Fixed by #49918
Closed

Upper-bounded generic type relaxes bigint restriction #49907

theonlypwner opened this issue Jul 14, 2022 · 0 comments Β· Fixed by #49918
Labels
Bug A bug in TypeScript
Milestone

Comments

@theonlypwner
Copy link

Bug Report

πŸ”Ž Search Terms

bug extends number bigint

πŸ•— Version & Regression Information

⏯ Playground Link

Playground link with relevant code

Playground link with original code from #44578

πŸ’» Code

type numberOrBigint = number | bigint;

function getKey(key: numberOrBigint) {
    // @ts-expect-error βœ”
    +key;
    // @ts-expect-error βœ”
    0 + key;
}

function getKey2<S extends numberOrBigint>(key: S) {
    // @ts-expect-error ❌ should error, but the compiler does not
    +key;
    // @ts-expect-error βœ”
    0 + key;
}

πŸ™ Actual behavior

+key is not an error in getKey2.

πŸ™‚ Expected behavior

It should be an error to be consistent with getKey, as S could be numberOrBigint instead of a more specific type.

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

Successfully merging a pull request may close this issue.

2 participants