moment / moment-timezone

Timezone support for moment.js
momentjs.com/timezone
MIT License
3.82k stars 835 forks source link

error TS2350: Only a void function can be called with the 'new' keyword. new moment(); #1081

Closed srivai-sundarraj closed 9 months ago

srivai-sundarraj commented 9 months ago

Hi Team,

I have upgraded "moment-timezone" from "0.5.23" to "0.5.43" on Angular application. Got the following issue

Only a void function can be called with the 'new' keyword.
var toDate = new moment();

if I use just moment() it is working fine. May I know the reason?. What is the difference between moment() and new moment() ?

My dependency "@types/node": "12.11.1", "typescript": "4.6.4" Angular CLI: 14.2.10 Node: 16.18.1

sslincoco commented 9 months ago

您的邮件已收到,我会尽快给您回复。

gilmoreorless commented 9 months ago

From the moment perspective, there's no difference between calling moment() and new moment(). Internally, Moment instances are objects with prototype methods that are created with the new keyword. But the public moment() function abstracts that detail away, so callers shouldn't need to care about it. The documentation doesn't use the new keyword in the examples, and it's not the recommended way to create Moment instances.

However, that error message doesn't come from this library. Perhaps it's from Angular validation tooling.

gilmoreorless commented 9 months ago

@sslincoco Can you please fix your email settings? It looks like your email client has auto-responded to a few issues in this repository, with the same message each time.