interface IUser {
name: string;
email: string;
phone: number;
}
type TAnswer = "Yes" | "No";
interface IApiService {
getUser(): IUser;
}
class ApiService implements IApiService {
/* ... */
}
interface IData {
name: string;
surname: string;
}
interface IAdmin extends IData {
/* ... */
}
Instead of
interface IData {
level: number;
}
Use
interface IData {
level: 1 | 2;
}
Instead of
interface IData {
level: number | undefined;
}
Use
interface IData {
level?: number;
}
import { ICommonData } from "@typings/data";
import { ILocalInfo } from "./typings";
declare module "data" {
export interface IPayload {
name: string;
password: string;
}
export function parseData(options: IPayload): void;
}
// for fonts
declare module "*.ttf";
interface IService {
getInfo: (token: string) => Promise<IData>;
}
Record
works good with object typings
const hashMap: Record<string, string> = {
name: "John",
surname: "Dou",
photoUrl: "...",
};
Also could be used for strict object validation
const hashMap: Record<'name' | 'surname' | 'photoUrl', string> = {
name: "John",
surname: "Dou",
photoUrl: "...",
};
Partial
will help you with typization of big objects
interface BigObject {
getName(): string;
getInfo(): Promise<Data>;
name: string;
photo: string;
}
const smallPart: Partial<BigObject> = {
name: "John",
photo: "...",
};