moment().add() only works with literal values

Deprecated reverse overload add(unit: unitOfTime.DurationConstructor, amount: number|string) creates ambiguity.

You can fix this by defining type of units to be DurationConstructor instead of string:

let units: moment.unitOfTime.DurationConstructor="month";
moment().add(1, units);

Another option is just to use const instead of let, so literal type will be inferred:

const units="month";
moment().add(1, units);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)