All files / src Array.js

100% Statements 7/7
100% Branches 2/2
100% Functions 5/5
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26          56x       5x 5x   14x     28x   8x             2x  
import { BaseType, coerce } from './base';
import nativeTypeMap from './nativeTypeMap';
 
export default class ArrayType extends BaseType {
  static isOfType(val) {
    return Array.isArray(val);
  }
 
  static ofType(memberType) {
    const coercedType = coerce(memberType);
    return class ArrayOfType extends this {
      static get type() {
        return coercedType;
      }
      static isOfType(val) {
        return super.isOfType(val) && val.every((itemVal) => {
          // console.log(this.type)
          return this.type.isOfType(itemVal)
        });
      }
    };
  }
}
 
nativeTypeMap.set(Array, ArrayType);