Skip to content

89 - Required Keys #2664

Open
Open

Description

@jiangshanmeta
type RequiredKeys<T , K = keyof T> = K extends keyof T ? T extends Required<Pick<T,K>> ? K : never
  :never

Activity

  1. added
    answer
    en
    on Aug 15, 2021
  2. dimitropoulos commented on Jan 16, 2023

    @dimitropoulos
    Contributor

    I really like how this solution works Required and Pick into it. It makes it read much easier. Thanks! I'll be featuring this in the video solutions!

  3. WisestCoder commented on Apr 19, 2023

    @WisestCoder
    type RequiredKeys<T> = keyof { [K in keyof T as {} extends Pick<T, K> ? never : K]: T[K] }
  4. iversonwool commented on May 15, 2024

    @iversonwool

    like the OptionalKeys

    type RequiredKeys<T> = {
      [P in keyof T]-?: {} extends Pick<T, P> ? never : P
    }[keyof T]
  5. HNHED commented on Dec 8, 2025

    @HNHED

    type RequiredKeys = keyof {[K in keyof T as T[K] extends Required[K] ? K: never]: K}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    89answeren

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions