Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S.omit fails on optional properties #144

Open
samhh opened this issue Sep 12, 2022 · 2 comments
Open

S.omit fails on optional properties #144

samhh opened this issue Sep 12, 2022 · 2 comments
Labels

Comments

@samhh
Copy link
Owner

samhh commented Sep 12, 2022

See: b3d8ab0, #141

Notably this isn't an issue with S.omitFrom.

@samhh samhh added the bug label Sep 12, 2022
@JLambertazzo
Copy link

JLambertazzo commented Mar 12, 2023

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

@samhh
Copy link
Owner Author

samhh commented Apr 7, 2023

@JLambertazzo Would that be backwards-compatible with uses of Record?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants