type WithPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; interface RequestOption { url: string, method: 'GET' | 'POST' | 'PUT', headers: {[key: string]: string}, body: string } interface ResponData { status: string, data: any, error: Error } function request(option: WithPartial<RequestOption, 'headers'|'body'>): Promise<Omit<ResponData, 'error'> | Omit<ResponData, 'data'>> { return Promise.resolve({ status: 'AT-400', data: {} }); }
WithPartial 为标题说的方法,该方法由两部分组成,
Omit<T, K> : 为从T中剔除K属性
Partial<Pick<T, K>> :Pick<T, K> 为从T中选出K属性,由Partial转为可选标签:WithPartial,status,转换,string,可选,Omit,TS,Partial From: https://www.cnblogs.com/ehuanrum/p/17538916.html