static isError()

Checks whether the value of any type is a this instance of any or the given identification

CommonError.isError()

Checks whether the value of any type is a this instance of any or the given identification.

common-error.class.ts
protected static isError<Id extends string>(
  value: any,
  id?: Id
): value is CommonError<Id> {
  return typeof value === 'object' && value instanceof this
    ? typeof id === 'string'
      ? value.id === id
      : true
    : false;
}

Generic type variables

Idextendsstring

A generic type variable constrained by the string indicates the

Parameters

value:any

The value of any type to check against the this instance.

id?:Id

Optional identification of generic type variable Id to check whether the given value contains.

Return type

value isCommonError<Id>

The return type is a boolean indicating the value is the CommonError object that takes generic type variable Id.

Returns

The return value is a boolean type indicating whether the given value is a this instance of any or the given id.

Example usage

// Example usage.
import { CommonError } from '@angular-package/error';

class TestError<Id extends string> extends CommonError<Id> {
  public static isError<Id extends string>(
    value: any,
    id?: Id
  ): value is TestError<Id> {
    return super.isError(value, id);
  }
}

const testError = new TestError(
  'Problem accessor.',
  'Fix accessor.',
  '(AE:427)',
  '{problem} {fix} {id}'
);

// Returns "true".
TestError.isError(testError, '(AE:427)');

Last updated