@@ -365,15 +365,20 @@ function parseInterfaceProperties(
365365 : `'${ propName } '` ;
366366 const isRequired = requiredProps . includes ( propName ) ;
367367
368+ const accessProp = ( arg : string ) : string =>
369+ arg . startsWith ( "'" ) ? `arg[${ arg } ]` : `arg.${ arg } ` ;
370+
368371 const guardFn = ( fn : ( ) => string , prop : Property = { } ) => `
369372 ${
370373 prop . hasOwnProperty ( 'isRequired' ) || isRequired
371374 ? ''
372- : `typeof arg. ${ name } === 'undefined' ||`
375+ : `typeof ${ accessProp ( name ) } === 'undefined' ||`
373376 }
374377 ${
375378 prop . isArray || isArray
376- ? `(Array.isArray(arg.${ name } ) && arg.${ name } .every((item: unknown) => ${
379+ ? `(Array.isArray(${ accessProp ( name ) } ) && ${ accessProp (
380+ name ,
381+ ) } .every((item: unknown) => ${
377382 prop . isPrimitiveType || isPrimitiveType
378383 ? `typeof item === '${ type } '`
379384 : `is${ prop . typescriptType || typescriptType } (item)`
@@ -386,7 +391,7 @@ function parseInterfaceProperties(
386391 } )`
387392 : `${
388393 prop . isPrimitiveType || isPrimitiveType
389- ? `typeof arg. ${ prop . name || name } === '${
394+ ? `typeof ${ accessProp ( prop . name || name ) } === '${
390395 ( prop . type || type ) === '{ [key: string]: any }'
391396 ? 'object'
392397 : prop . type || type
@@ -400,15 +405,18 @@ function parseInterfaceProperties(
400405 propertyAllOf . length
401406 ? `(${ propertyAllOf
402407 . map ( prop =>
403- guardFn ( ( ) => `is${ prop . typescriptType } (arg.${ name } )` , prop ) ,
408+ guardFn (
409+ ( ) => `is${ prop . typescriptType } (${ accessProp ( name ) } )` ,
410+ prop ,
411+ ) ,
404412 )
405413 . join ( ' && ' ) } )`
406414 : / \| / . test ( typescriptType )
407415 ? `[${ ( typescriptType || '' ) . replace (
408416 / \| / g,
409417 ', ' ,
410- ) } ].includes(arg. ${ name } )`
411- : `is${ typescriptType } (arg. ${ name } )` ,
418+ ) } ].includes(${ accessProp ( name ) } )`
419+ : `is${ typescriptType } (${ accessProp ( name ) } )` ,
412420 ) . replace ( / \s + / g, ' ' ) } ) &&`;
413421
414422 return {
0 commit comments