TS高级操作

interface Todo {
    title: string;
    description: string;
    completed: boolean;
}
interface Todo1 {
    completed:boolean;
    title:string;
}
type B = number | boolean
type C = boolean | undefined
type Select = 'title'|'description'

type A1 = Pick<Todo,'title'|'completed'>//选取指定

type A2 = Partial<Todo> //变成可选

type A11 = Partial<Pick<Todo,Select>>//先Pick选取指定的,再变成可选

type A3 = Required<Todo>//变成必选

type A4 = Omit<Todo,'title'>//排除

type A5 = Exclude<B,C>//选出不一样的,排除掉交集

type A6 = Omit<Todo,Select>

type A7 = A11 & A6
const s:A7 = {
    completed:true,
    title:'ii',
    description:'shi'
}
//部门可选,部分不可选
type SelectPartial<T,V extends keyof T> = Partial<Pick<T,V>> & Omit<T,V> //
type Final = SelectPartial<Todo,Select>
const code:Final = {
    completed:true,
    description:'bai'
}

 

上一篇:CentOS7网卡的命名规则


下一篇:ts 限制输入框只能输入一个 emoji 表情