Skip to content

Upper-bounded generic type relaxes bigint restrictionΒ #49907

Closed
@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