CódigoNão tentada
Desafio de tipos: Partial, Required, Exclude, Extract
Dificuldade: média
Reimplemente Partial, Required (dica: o modificador -?), Exclude e Extract (dica: conditional types se distribuem sobre uniões) e depois PartialBy<T, K>, que torna opcionais apenas as chaves K.
Ver solução de referência
export type MyPartial<T> = { [P in keyof T]?: T[P] };export type MyRequired<T> = { [P in keyof T]-?: T[P] }; // -? removes optionality// Conditional types distribute over unions, so each member is tested on its own.export type MyExclude<T, U> = T extends U ? never : T;export type MyExtract<T, U> = T extends U ? T : never;export type PartialBy<T, K extends keyof T> = Omit<T, K> & { [P in K]?: T[P] };
Ctrl Enter