File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,19 +130,21 @@ class RpcStruct {
130130 * @param {Boolean } isArray - Whether or not the given variable is an array to be iterated through.
131131 */
132132 _validateType ( tClass , obj , isArray = false ) {
133- if ( isArray ) {
134- if ( ! Array . isArray ( obj ) ) {
135- throw new Error ( `${ obj . name } must be an array containing items of type ${ tClass . name } ` ) ;
136- } else {
137- for ( const item of obj ) {
138- this . _validateType ( tClass , item , false ) ;
133+ if ( obj !== null ) {
134+ if ( isArray ) {
135+ if ( ! Array . isArray ( obj ) ) {
136+ throw new Error ( `${ obj . name } must be an array containing items of type ${ tClass . name } ` ) ;
137+ } else {
138+ for ( const item of obj ) {
139+ this . _validateType ( tClass , item , false ) ;
140+ }
139141 }
142+ } else if (
143+ ( tClass . prototype instanceof Enum && tClass . keyForValue ( obj ) === null )
144+ || ( tClass . prototype instanceof RpcStruct && obj . constructor !== tClass )
145+ ) {
146+ throw new Error ( `${ obj . name } must be of type ${ tClass . name } ` ) ;
140147 }
141- } else if (
142- ( tClass . prototype instanceof Enum && tClass . keyForValue ( obj ) === null )
143- || ( tClass . prototype instanceof RpcStruct && obj !== null && obj . constructor !== tClass )
144- ) {
145- throw new Error ( `${ obj . name } must be of type ${ tClass . name } ` ) ;
146148 }
147149 }
148150}
You can’t perform that action at this time.
0 commit comments