Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

ObjectOmit doesnt preserve optional keys #12

Closed
ccorcos opened this issue Nov 3, 2017 · 4 comments
Closed

ObjectOmit doesnt preserve optional keys #12

ccorcos opened this issue Nov 3, 2017 · 4 comments

Comments

@ccorcos
Copy link

ccorcos commented Nov 3, 2017

No description provided.

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Mar 9, 2018

You may have ran into this TS bug: microsoft/TypeScript#20722

type Foo =
  | {
      optionalProp?: string;
    }
  | {
      optionalProp?: string;
    };

// `optionalProp` is no longer optional
type Foo2 = Pick<Foo, keyof Foo>;

@OliverJAsh
Copy link
Contributor

I believe we can fix this now with conditional types:

type Omit<T, K extends keyof T> = T extends any ? Pick<T, Exclude<keyof T, K>> : never

microsoft/TypeScript#12215 (comment)

@gcanti
Copy link
Owner

gcanti commented Jul 27, 2018

AFAIK In v0.3 Omit does preserve optional props

interface A {
  a: string
  b?: number
  c: boolean
}

type B = Omit<A, 'a'>
/*
type B = {
    b?: number | undefined;
    c: boolean;
}
*/

@gcanti gcanti closed this as completed Jul 27, 2018
@OliverJAsh
Copy link
Contributor

Oops, I was supposed to post that comment in #11.

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

No branches or pull requests

3 participants