Skip to content

minus operator - does not necessarily return a numberΒ #56162

Closed as not planned
Closed as not planned
@yukulele

Description

@yukulele

πŸ”Ž Search Terms

"minus operator", "minus bigint", "minus any"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "operator"

⏯ Playground Link

https://www.typescriptlang.org/play?target=7#code/MYewdgzgLgBAhgLjmAnjAvDAjABjAKABsBTWAIwxgFo58KBqTAViA

πŸ’» Code

const a:any = 10n
let b = -a
b += 5 
// - tsc: no error
// - run: can't convert BigInt to number

πŸ™ Actual behavior

b type is number

πŸ™‚ Expected behavior

b type should be number | bigint

Additional information about the issue

Here's another example showing that other operators can potentially be affected

class A { [Symbol.toPrimitive] = () => 1n }

const a: A = new A()

const b = a.valueOf()
const c = -a
const d = ~a
// `b`, `c` and `d` types shound be `bigint`, right?

https://www.typescriptlang.org/play?target=7#code/MYGwhgzhAECC0G9oG0DKBPAtgIwPYgDoAXXABQCcBLTSoygNwFMBdaAXmgAoBKdgPmgBGAHbQAvgCgJwXMIhFoYAFxx20YYwDucHlJlyF2NWAL0wIAK6MA8gDNd++dGBqAtGGmynAEzUA-DwB6QOgAA2xQgBow4FDFYV9Q7ziidAAHRhgIAAtcCwTobEYw7EoAc0phIlCgA

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions