Omit
linjunc opened this issue · 1 comments
linjunc commented
实现 TS 中的 Omit 方法
interface Todo {
title: string
description: string
completed: boolean
}
type MyOmit<T, K extends keyof T> = {
[R in keyof T as R extends K ? never: R ]: T[R]
}
type TodoPreview = MyOmit<Todo, 'description' | 'title'>
Aurora-GSW commented
type MyPick<T, K extends keyof T> = {
[p in K]:T[p]
}
//实现1
type MyOmit<T, K extends keyof any> = MyPick<T,Exclude<keyof T,K>>
//实现2
type MyOmit<T, K extends keyof any> = {
[p in Exclude<keyof T,K>]:T[p]
}