Repository: oppia/oppia
File: core/templates/domain/exploration/param-type.model.ts (TypeScript)

Code before:
  // It depends on the arguments passed to the constructor.
  default_value: Object;
}

interface RegistryType {
  [key: string]: ParamType;
}

export class ParamType {
  _name: string;
  valueIsValid: (arg0: Object) => boolean;
  defaultValue: Object;

  /** @private @static */
  private static isInitialized = false;

  // Type registration.
  /** @type {Object.<String, ParamType>} */
  private static registry: Record<string, ParamType> = {
    UnicodeString: new ParamType({
      validate: (value: Object) => {
        return typeof value === 'string' || value instanceof String;
      },
      default_value: '',
    }),
  };

  /**
   * @private @constructor
   * Defines a specific type that a parameter can take.
   *
   * IMPORTANT: All new types must be created in this file and registered in the
   * {@link ParamType.registry}. See {@link ParamType.registry.UnicodeString}
   * for an example.
   *
   * @param {Function.<?, Boolean>} validateFunction - Returns true when a value
   * is valid.
   * @param {Object} defaultValue - simple value any parameter of this type can
   * take.
   */

  constructor(typeDefinitionObject: TypeDefinitionObject) {
    if (!typeDefinitionObject.validate(typeDefinitionObject.default_value)) {
      throw new Error(
        'The default value is invalid according to validation function'
      );
    }

    /** @member {String} */
    this._name = '';
    /** @member {Function.<Object, Boolean>} */

Review comment (suggestion):
I meant delete this, and declare it like ``private static registry: Record<string, ParamType> = {};``

Code after:
  // It depends on the arguments passed to the constructor.
  default_value: Object;
}

export class ParamType {
  _name: string;
  valueIsValid: (arg0: Object) => boolean;
  defaultValue: Object;

  // Type registration.
  /** @type {Object.<String, ParamType>} */
  private static registry: Record<string, ParamType> = ParamType.initRegistry();

  /**
   * @private @constructor
   * Defines a specific type that a parameter can take.
   *
   * IMPORTANT: All new types must be created in this file and registered in the
   * {@link ParamType.registry}. See {@link ParamType.registry.UnicodeString}
   * for an example.
   *
   * @param {Function.<?, Boolean>} validateFunction - Returns true when a value
   * is valid.
   * @param {Object} defaultValue - simple value any parameter of this type can
   * take.
   */

  constructor(typeDefinitionObject: TypeDefinitionObject) {
    if (!typeDefinitionObject.validate(typeDefinitionObject.default_value)) {
      throw new Error(
        'The default value is invalid according to validation function'
      );
    }

    /** @member {String} */
    this._name = '';
    /** @member {Function.<Object, Boolean>} */
    this.valueIsValid = typeDefinitionObject.validate;
    /** @member {Object} */
    this.defaultValue = typeDefinitionObject.default_value;
  }

  private static initRegistry(): Record<string, ParamType> {
    const definitions: Record<string, TypeDefinitionObject> = {
      UnicodeString: {
        validate: (value: Object) =>
          typeof value === 'string' || value instanceof String,
        default_value: '',
      },
    };