arco-design
arco-design copied to clipboard
Form validate return eternal pending promise while pass `undefined` as a parameter
- [] I'm sure this does not appear in the issue list of the repository
Basic Info
- Package Name And Version: @arco-design/[email protected]
- Browser: chrome104.0.0.0
- Reproduction Link: https://codesandbox.io/s/sad-shape-rjyq8b?file=/demo.js
Steps to reproduce
- Write a form item rule validator which return a Promise
- Use form.validate()
I reckon this issue is related to the implementation of components/Form/promisify.ts
which implemented first default function parameter wrongly.
function promisify<T = any>(fn: (...args: any[]) => any): () => Promise<T> {
return Object.defineProperty(
function (...args: any[]) {
if (typeof args[args.length - 1] === 'function') fn.apply(this, args);
else {
return new Promise((resolve, reject) => {
args[args.length] = (err, res) => {
if (err) return reject(new ValidateError(err));
resolve(res);
};
args.length++;
fn.apply(this, args);
});
}
},
'name',
{ value: fn.name }
);
}