Repository: facebook/jest
File: packages/jest-reporters/src/SummaryReporter.ts (TypeScript)

Code before:
]);

const {npm_config_user_agent, npm_lifecycle_event, npm_lifecycle_script} =
  process.env;

export default class SummaryReporter extends BaseReporter {
  private _estimatedTime: number;
  private readonly _globalConfig: Config.GlobalConfig;
  private readonly _summaryThreshold: number;

  static readonly filename = __filename;

  constructor(
    globalConfig: Config.GlobalConfig,
    options: SummaryReporterOptions = {},
  ) {
    super();
    this._globalConfig = globalConfig;
    this._estimatedTime = 0;
    this.validateOptions(options);
    this._summaryThreshold = options.summaryThreshold || 20;
  }

  private validateOptions(options: SummaryReporterOptions) {
    if (
      options.summaryThreshold &&
      typeof options.summaryThreshold !== 'number'
    ) {
      throw new TypeError('The option summaryThreshold should be a number');
    }
  }

  // If we write more than one character at a time it is possible that
  // Node.js exits in the middle of printing the result. This was first observed
  // in Node.js 0.10 and still persists in Node.js 6.7+.
  // Let's print the test failure summary character by character which is safer
  // when hundreds of tests are failing.
  private _write(string: string) {
    for (let i = 0; i < string.length; i++) {
      process.stderr.write(string.charAt(i));
    }
  }

  override onRunStart(
    aggregatedResults: AggregatedResult,
    options: ReporterOnStartOptions,
  ): void {
    super.onRunStart(aggregatedResults, options);
    this._estimatedTime = options.estimatedTime;
  }


Review comment (suggestion):
Would be good to prepend underscore just like in other private methods. Optional chaining and nullish coalescing also looks good here.

```suggestion
    options?: SummaryReporterOptions,
  ) {
    super();
    this._globalConfig = globalConfig;
    this._estimatedTime = 0;
    this._validateOptions(options);
    this._summaryThreshold = options?.summaryThreshold ?? 20;
  }

  private _validateOptions(options?: SummaryReporterOptions) {
    if (
      options?.summaryThreshold &&
```

Code after:
]);

const {npm_config_user_agent, npm_lifecycle_event, npm_lifecycle_script} =
  process.env;

export type SummaryReporterOptions = {
  summaryThreshold?: number;
};

export default class SummaryReporter extends BaseReporter {
  private _estimatedTime: number;
  private readonly _globalConfig: Config.GlobalConfig;
  private readonly _summaryThreshold: number;

  static readonly filename = __filename;

  constructor(
    globalConfig: Config.GlobalConfig,
    options?: SummaryReporterOptions,
  ) {
    super();
    this._globalConfig = globalConfig;
    this._estimatedTime = 0;
    this._validateOptions(options);
    this._summaryThreshold = options?.summaryThreshold ?? 20;
  }

  private _validateOptions(options?: SummaryReporterOptions) {
    if (
      options?.summaryThreshold &&
      typeof options.summaryThreshold !== 'number'
    ) {
      throw new TypeError('The option summaryThreshold should be a number');
    }
  }

  // If we write more than one character at a time it is possible that
  // Node.js exits in the middle of printing the result. This was first observed
  // in Node.js 0.10 and still persists in Node.js 6.7+.
  // Let's print the test failure summary character by character which is safer
  // when hundreds of tests are failing.
  private _write(string: string) {
    for (let i = 0; i < string.length; i++) {
      process.stderr.write(string.charAt(i));
    }
  }

  override onRunStart(
    aggregatedResults: AggregatedResult,
    options: ReporterOnStartOptions,
  ): void {