Skip to content

Upper-bounded generic type relaxes bigint restriction #49907

@theonlypwner

Description

@theonlypwner

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions