Skip to content

Instantly share code, notes, and snippets.

@HenriqueSilverio
Created April 4, 2022 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HenriqueSilverio/898d9e3baac58586584c77b3827670ea to your computer and use it in GitHub Desktop.
Save HenriqueSilverio/898d9e3baac58586584c77b3827670ea to your computer and use it in GitHub Desktop.
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
type Test = {
foo: string,
bar: string,
baz: string,
daz?: string,
}
type Test1 = Optional<Test, 'foo'>
const test1: Test1 = {
bar: '',
baz: '',
}
type Test2 = Optional<Test, 'bar' | 'baz'>
const test2: Test2 = {
foo: '',
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment