TS6387

The signature (from: number, length?: number | undefined): string of error.substr is deprecated.

Broken Code ❌

function parseErrorCode(error: string): number {
  return parseInt(error.substr(2, 4).trim(), 10);
}
 
console.log(parseErrorCode('TS12345')); // "1234"

Fixed Code ✔️

Use the slice method instead of substr, but be careful about the supplied parameters as the signature is slightly different:

function parseErrorCode(error: string): number {
  return parseInt(error.slice(2, 6).trim(), 10);
}
 
console.log(parseErrorCode('TS12345')); // "1234"