@centigrade/hypertyper
v1.1.0
Published
A set of utility types helping with common code tasks.
Keywords
Readme
HyperTyper
This package contains useful types helping you with common code tasks across different TypeScript projects.
Included Types
PublicApi<T>
This type takes another type and refers to all of its public methods of the class. This type is useful if you want to create an alternative implementation of an existing class and make sure that both classes stay in sync.
import type { PublicApi } from "@centigrade/hypertyper";
export class UserService {
public count = 0;
public add(user: User) {}
public remove(user: User) {}
}
/*
By implementing PublicApi<UserService> all refactorings
on public methods of UserService will also take effect on
this class. Also TypeScript will complain about this class if
there are UserService has public methods that are missing here.
*/
export class UserMockService implements PublicApi<UserService> {
public count = 0;
public add(user: User) {}
public remove(user: User) {}
}PublicMembers<T>
This type is similar to PublicApi<T> but not only refers to public methods, but all public class members. This type is useful if you want to create an alternative implementation of an existing class and make sure that both classes stay in sync.
import type { PublicMembers } from "@centigrade/hypertyper";
export class UserService {
public count = 0;
public add(user: User) {}
public remove(user: User) {}
}
/*
By implementing PublicMembers<UserService> all refactorings
on public members of UserService will also take effect on
this class. Also TypeScript will complain about this class if
there are any differences between these classes.
*/
export class UserMockService implements PublicMembers<UserService> {
public count = 0;
public add(user: User) {}
public remove(user: User) {}
}