Доки по разработке
This project is maintained by teniryte
Принципы
type) подходят для описания примитивов, объединений, кортежей и функций — интерфейсы не справятся с этими случаями.extends) и declaration merging (слияние объявлений).Пример
type Names1 = string[];
interface Names2 {
[index: number]: string;
}
type Point = [number, number]; // интерфейс так не может
type LogFn = (message: string) => void;
interface LogInterface {
(message: string): void;
}
interface ButtonProps {
text: string;
onClick: () => void;
}
interface ButtonProps {
id: string;
} // declaration merging
Практика
type Actions = A | B | C;) и производных типов (type Contact = Name & PhoneNumber;).