我有以下类型/接口:
type Nullable<T> = T | null;
export interface Employee {
name: string;
salary: number;
}我不想将Employee的属性定义为Nullable,但是整个Employee应该是Nullable。
因为我不想每次都像Nullable<Employee>一样使用它。我宁愿把它输入为Employee,然后自动成为Employee | null
发布于 2022-01-25 21:43:23
您需要一个类型别名:
export type Employee = {
name: string;
salary: number;
} | nullhttps://stackoverflow.com/questions/70855911
复制相似问题