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

Subtracting Date objects shows a TypeScript error, but actually works. #58400

Closed
ScottHenshaw86 opened this issue May 2, 2024 · 5 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@ScottHenshaw86
Copy link

πŸ”Ž Search Terms

"Date arithmetic"

πŸ•— Version & Regression Information

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

⏯ Playground Link

No response

πŸ’» Code

const a = new Date();
const b = new Date();
const c = a - b;

πŸ™ Actual behavior

TypeScript shows error: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2362)

πŸ™‚ Expected behavior

No error because the operation works.

Additional information about the issue

No response

@pavanputhra
Copy link

+1

@Andarist
Copy link
Contributor

Andarist commented May 2, 2024

https://stackoverflow.com/questions/41750390/what-does-all-legal-javascript-is-legal-typescript-mean/41750391#41750391

If you want to subtract date objects - please cast them to numbers first.

@MartinJohns
Copy link
Contributor

Duplicate of #5710.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 2, 2024
@RyanCavanaugh
Copy link
Member

See also #2361 (comment)

@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 May 5, 2024
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

6 participants