@@ -226,9 +226,14 @@ function validateParams(p5, fn, lifecycles) {
226226 const isOptional = param ?. endsWith ( '?' ) ;
227227 param = param ?. replace ( / \? $ / , '' ) ;
228228
229- let schema = generateTypeSchema ( param ) ;
229+ const isRest = param ?. startsWith ( '...' ) && param ?. endsWith ( '[]' ) ;
230+ param = param ?. replace ( / ^ \. \. \. ( .+ ) \[ \] $ / , '$1' ) ;
230231
231- return isOptional ? schema . optional ( ) : schema ;
232+ let schema = generateTypeSchema ( param ) ;
233+ if ( isOptional ) {
234+ schema = schema . optional ( ) ;
235+ }
236+ return { schema, rest : isRest } ;
232237 } ;
233238
234239 // Note that in Zod, `optional()` only checks for undefined, not the absence
@@ -262,14 +267,22 @@ function validateParams(p5, fn, lifecycles) {
262267 const overloadSchemas = overloads . flatMap ( overload => {
263268 const combinations = generateOverloadCombinations ( overload ) ;
264269
265- return combinations . map ( combo =>
266- z . tuple (
267- combo
268- . map ( p => generateParamSchema ( p ) )
269- // For now, ignore schemas that cannot be mapped to a defined type
270- . filter ( schema => schema !== undefined )
271- )
272- ) ;
270+ return combinations . map ( combo => {
271+ const params = combo
272+ . map ( p => generateParamSchema ( p ) )
273+ . filter ( s => s . schema !== undefined ) ;
274+
275+ let rest ;
276+ if ( params . at ( - 1 ) ?. rest ) {
277+ rest = params . pop ( ) ;
278+ }
279+
280+ let combined = z . tuple ( params . map ( s => s . schema ) ) ;
281+ if ( rest ) {
282+ combined = combined . rest ( rest . schema ) ;
283+ }
284+ return combined ;
285+ } ) ;
273286 } ) ;
274287
275288 return overloadSchemas . length === 1
@@ -504,7 +517,7 @@ function validateParams(p5, fn, lifecycles) {
504517 // theoretically allowed to stay undefined and valid, it is likely that the
505518 // user intended to call the function with non-undefined arguments. Skip
506519 // regular workflow and return a friendly error message right away.
507- if ( Array . isArray ( args ) && args . every ( arg => arg === undefined ) ) {
520+ if ( Array . isArray ( args ) && args . length > 0 && args . every ( arg => arg === undefined ) ) {
508521 const undefinedErrorMessage = `🌸 p5.js says: All arguments for ${ func } () are undefined. There is likely an error in the code.` ;
509522
510523 return {
0 commit comments