Skip to content

minus operator - does not necessarily return a number #56162

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

Closed
yukulele opened this issue Oct 20, 2023 · 2 comments
Closed

minus operator - does not necessarily return a number #56162

yukulele opened this issue Oct 20, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@yukulele
Copy link

πŸ”Ž 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

@MartinJohns
Copy link
Contributor

Duplicate of #49558.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Oct 20, 2023
@typescript-bot
Copy link
Collaborator

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

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
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