Skip to content

Instantly share code, notes, and snippets.

@yashaka
Created April 21, 2022 20:28
Show Gist options
  • Save yashaka/e77a03e71464d742609595a09d806220 to your computer and use it in GitHub Desktop.
Save yashaka/e77a03e71464d742609595a09d806220 to your computer and use it in GitHub Desktop.
// виходить тут як раз воно не вилазить
function processResponse({response, ...rest}: {response: object} & {[key: string]: any}): {response: object;} & {[key: string]: any} {
// do something with response
return {response, ...rest}
}
// вилазити починає саме коли з'являється обмження що саме конкретно той тип А що зайшов на вхід то той і має вийти на виході...
function processResponse_<A>({response, ...rest}: {response: object} & A): {response: object;} & A {
// do something with response
return {response, ...rest} // <<<<<< TYPE ERROR
}
// і щоб це пофіксити, треба робити так:
function processResponse__<A>({response, ...rest}: {response: object} & A): {response: object;} & Omit<{response: object;} & A, 'response'> {
// do something with response
return {response, ...rest}
}
// виходить насправді моє питання таке - чи можна придумати якийсь спосіб що спростить останню сигнатуру? типу щось таке:
type ExtendedBy = undefined // TODO: implement
function processResponse___<A>({response, ...rest}: {response: object} & A): Extended<{response: object}, A> {
// do something with response
return {response, ...rest}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment