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
Description
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';
}