-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
dayjs(undefined).isValid() show devHelper warn in development #1240
Comments
I don't know how to get |
Thanks, it's a great idea to add some warning to DelHelper for a better development experience. However, in this case, |
I think the key point is
我认为这个关键点是 dayjs() 和 dayjs(undefined) 其实是有区别的,但是
Line 38 in eb5fbc4
Apart from the above reasons, the execution However, the high probability of executing Now At the very least, a warning should be provided in development mode when the
抛开以上的原因,在生产环境中执行 而在生产环境中执行 现在因为 那么至少应该在执行 // add code after https://github.com/iamkun/dayjs/blob/eb5fbc4c7d1b62a8615d2f263b404a9515d8e15c/src/plugin/devHelper/index.js#L16
const oldIsValid = proto.isValid;
proto.isValid= function () {
const cfg = this.xxxx; // <---- can't found `cfg` in Dayjs Class
const args = cfg.args;
if (Object.keys(args).length > 0 && args[0] === undefined ){
console.warn(`To parse a date-time string is undefined, dayjs(undefined) === dayjs() . https://day.js.org/docs/en/parse/now`);
}
return oldIsValid.bind(this)()
} |
Nice catch. It's good to add a dev warn while passing |
Describe the bug
This is not a bug
Expected behavior
I think the motivation for executing the
isvalid()
function is to verify that the input parameter value is valid. Because it makes no sense to executedayjs().isvalid()
in the production environment.When the input parameter is
undefined
, it is more likely that the input parameter isundefined
rather than the value is not passed.Since there is no way to tell whether the input parameter is undefined or not passed in, I recommend that you provide a warning in development mode.
我认为执行
isValid()
函数时的动机是验证入参值是否为有效。因为在生产环境执行dayjs().isvalid()
是没有意义的。当入参为
undefined
时多半是因为入参为undefined
,而非未传值。因为无法区分入参为
undefined
还是入参未传入,因此我建议在开发模式提供警告。Information
The text was updated successfully, but these errors were encountered: