Repository: react-hook-form/react-hook-form
File: src/types/utils.ts (TypeScript)

Code before:

export type NonUndefined<T> = T extends undefined ? never : T;

export type LiteralToPrimitive<T extends any> = T extends string
  ? string
  : T extends number
  ? number
  : T extends boolean
  ? boolean
  : T;

export type LiteralUnion<T extends U, U extends Primitive> =
  | T
  | (U & { _?: never });

export type Assign<T extends object, U extends object> = T & Omit<U, keyof T>;

export type DeepPartial<T> = {
  [K in keyof T]?: T[K] extends Array<infer U>
    ? Array<DeepPartial<U>>
    : T[K] extends ReadonlyArray<infer U>
    ? ReadonlyArray<DeepPartial<U>>
    : T[K] extends Record<string, unknown>
    ? DeepPartial<T[K]>
    : T[K];
};

export type IsAny<T> = boolean extends (T extends never ? true : false)
  ? true
  : false;

export type DeepMap<T, TValue> = {
  [K in keyof T]?: IsAny<T[K]> extends true
    ? any
    : NonUndefined<T[K]> extends NestedValue | Date | FileList
    ? TValue
    : NonUndefined<T[K]> extends object
    ? DeepMap<T[K], TValue>
    : NonUndefined<T[K]> extends Array<infer U>
    ? IsAny<U> extends true
      ? Array<any>
      : U extends NestedValue | Date | FileList
      ? Array<TValue>
      : U extends object
      ? Array<DeepMap<U, TValue>>
      : Array<TValue>
    : TValue;
};

export type IsFlatObject<T extends object> = Extract<
  Exclude<T[keyof T], NestedValue | Date | FileList>,

Review comment (suggestion):
Previous `DeepPartial<T>` breaks `unknown` type as `{}` because `T` is implicitly assumed as something keyed object.

try the new and old one in typescript playground: https://www.typescriptlang.org/play?#code/C4TwDgpgBA8gNgEwCIQmACgQwE7AJaZwA8AKgHxQC8UA3gFBRQDaA0lHgHZQDWEIA9gDMoJALoB+AFwjWoqBAAewCBwQBnKAEFs2TCCKdBEbFACqZBoyjitOvURRosuAsXMWrUaSVnylK9SgAJQhMBH4OOBBtXX1DYzMPKxsQsIiomPtHDBx8QiJ3S0ZvX0VlVQ0QgGN+bAQiNWBsTgBzABooAFcObg5+AHcOJMYbbOc84h8WUWGvGWmAbjoAXyW6UEgoMdzXUgpqEj9ywMy4jiMTcyLrW1iHVByXfMLPbyOAytDwyOi7M4vEtcUl90r87tsnm4yLM3mUPsEIDU6g0mq0Ot1egMhkDaMw2JweHwhCIJNIIRNSLIyMtrt41ghEXAcNAahxGlAACQAOQgjQgCAAaoROhBpN08ABHEVQNQgAC2ACN+HA1oowLVgFANtAeXzBcKIERLCQhXBpXCKl0en1Bkw5AAfBFI+qNZocdpWzGDfbXR0Ym0cO2+p21F2o93o61Yiz7WiWJjc3nKfVmiCiaQcCAAN2MS2WUAAZCJTSK1tqzBwwJgqtxdcmS4byFQRO9LXX+Q2DOcElcRmZLLD-JakJhlFBHQAxPBwCAAGTwjUsNhIA5bFsC1VDKLdHv90aXuNY7C4vAEwjE0lMlertaTHYNlOmFBpxREZfA0Hnyl0cBI-HQzRyng+A5qQraBJgHAgLGhzrhorqtAeCHuqusFDoEHCdIqxgHph2HYKh4EaEqyqhBwB4kTOkGoe+mxThAiANs29CMK60jIe0liYXATIKjOGZYQqCSOtxKqWPwYD4BEhACfh45WgygicPySyMDgsTSDQAAW-AtKKUB4UJ2AdIInQtJg7Hhi0yxBjS6wfrAiAAMoQMADYkB+RqMCQ9GMQaGhwSGyIcR0kHQW0xq+QgXKYHK0CBSFkV4AxKbmuhGg+clfmpmoTCZSlMVxXIBxRQ2uX5YghVpnQsZXlWNbtqlhrwMgDzjLsX7GIQf4AXgQEgY2pUGtCFj2ZsLluQaHmQF5IhDTlRFBWGO6hVBZARd5UVVYtiWbVlTWLRVTXlVtsVps2R1lXlp1FTVzZ1TejWduSHXAV1v7-oBwF4KBl3DdCdBjdALXNi1E3uZ580ih0HFkEs5ZcgMzbg1NkP7Q2MNWXDdBAA

Code after:

export type NonUndefined<T> = T extends undefined ? never : T;

export type LiteralToPrimitive<T extends any> = T extends string
  ? string
  : T extends number
  ? number
  : T extends boolean
  ? boolean
  : T;

export type LiteralUnion<T extends U, U extends Primitive> =
  | T
  | (U & { _?: never });

export type Assign<T extends object, U extends object> = T & Omit<U, keyof T>;

export type DeepPartial<T> = T extends Array<infer U>
  ? Array<DeepPartial<U>>
  : T extends ReadonlyArray<infer U>
  ? ReadonlyArray<DeepPartial<U>>
  : T extends Record<string, unknown>
  ? {
      [K in keyof T]?: DeepPartial<T[K]>;
    }
  : T;

export type IsAny<T> = boolean extends (T extends never ? true : false)
  ? true
  : false;

export type DeepMap<T, TValue> = {
  [K in keyof T]?: IsAny<T[K]> extends true
    ? any
    : NonUndefined<T[K]> extends NestedValue | Date | FileList
    ? TValue
    : NonUndefined<T[K]> extends object
    ? DeepMap<T[K], TValue>
    : NonUndefined<T[K]> extends Array<infer U>
    ? IsAny<U> extends true
      ? Array<any>
      : U extends NestedValue | Date | FileList
      ? Array<TValue>
      : U extends object
      ? Array<DeepMap<U, TValue>>
      : Array<TValue>
    : TValue;
};

export type IsFlatObject<T extends object> = Extract<
  Exclude<T[keyof T], NestedValue | Date | FileList>,