Typescript: create union instead intersection when merging optional with required type
问题 When optional and required property are merged via intersection, required wins type A = { who: string } type B = { who?: string } // $ExpectType {who:string} type R = A & B This may lead to runtime errors, when for instance, dealing with default params pattern within a function type Params = { who: string greeting: string } const defaults: Params = { greeting: 'Hello', who: 'Johny 5', } function greeting(params: Partial<Params>){ // $ExpectType Params const merged = {...defaults, ...params}