Open samhh opened 2 years ago
This could be achieved by replacing the use of Record in this module to something that looks more like a Struct. I've been using the type definitions to test some things with
type Struct = {[key: string]: unknown}
type StructWithKey<K extends string> = {[key in K]?: unknown} & Struct
Using these types we can define an omit function where the generic struct A is defined by the generic key K
const omit = <K extends string>(keys:readonly K[]) => <A extends StructWithKey<K>>(struct: A): Omit<A, K> => {
const y = {...struct}
for (const key of keys) {
delete y[key]
}
return y
}
This successfully omits specified fields and doesn't remove typing from other parameters after omit
@JLambertazzo Would that be backwards-compatible with uses of Record
?
See: b3d8ab0e52, #141
Notably this isn't an issue with
S.omitFrom
.