Skip to content
This repository has been 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 opened this issue May 9, 2019 · 0 comments
Open

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

mayurkale22 opened this issue May 9, 2019 · 0 comments

Comments

@mayurkale22
Copy link
Member

mayurkale22 commented May 9, 2019

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';
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant