Typeof
Syntax
type Typeof<T>
Utility type that transforms a TypeofResult
into the type it represents.
Example
import { TypeofResult, Typeof } from 'potence';
function checkType<T extends TypeofResult>(object: unknown, type: T): object is Typeof<T> {
return typeof object === type;
}
let object: unknown = 'foo';
if (checkType(object, 'string')) {
// In this block, TypeScript knows that object is of type string
object = object.toLowerCase(); // no error
}
Remarks
See TypeofResult
.