Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kenmori/bda57da1ac6804b2c30b8e9cf9d16dbd to your computer and use it in GitHub Desktop.
Save kenmori/bda57da1ac6804b2c30b8e9cf9d16dbd to your computer and use it in GitHub Desktop.
Separate optional and required types that can have null types

Separate optional and required types that can have null types

type NullAbleType<T> = {[K in keyof T]: T[K] | null}
type Option = { money: number, fn: (...arg: any[])=> void}
type User = {name: string, age: number}
type UserWithOPtionNullAble = User & NullAbleType<Partial<Option>>

// const obj:UserWithOPtionNullAble = {name: "kenji", age: 99, money: 222, fn: ()=>{}}

const obj = {} as UserWithOPtionNullAble
obj.age = 99
obj.name = "kenji"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment