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' }
标签:description,title,completed,Omit,TS,高级,boolean,操作,type 来源: https://www.cnblogs.com/MDGE/p/15696681.html