Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Metrics/Utils: Consider to use unknown type instead of any #512

Open
@mayurkale22

Description

@mayurkale22

Consider to use unknown type instead of any for Metrics Utils functions.

Fact: unknown acts like a type-safe version of any by requiring us to perform some type of checking before we can use the value of the unknown element or any of its properties.

Dependency on #279 (unknown type is available since TypeScript 3.0).

Example usage:

export function isLengthMethodInterface(obj: unknown):
    obj is LengthMethodInterface {
  return _isSizeAttributeInterface(obj);
}

// Performs a structural check on given object.
// tslint:disable-next-line:no-any
function _isSizeAttributeInterface(obj: any): boolean {
  return !!obj && typeof obj === 'object' && 'size' in obj &&
      typeof obj.size === 'number';
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions