Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key_Type from props #20901

Open
lvjiaxuan opened this issue Dec 20, 2022 · 1 comment · May be fixed by #20902
Open

Key_Type from props #20901

lvjiaxuan opened this issue Dec 20, 2022 · 1 comment · May be fixed by #20902
Labels
new-challenge Propose a new challenge, a PR will be auto generated

Comments

@lvjiaxuan
Copy link
Contributor

lvjiaxuan commented Dec 20, 2022

Please follow the template and fill the info. A PR will be auto-generated and always reflect on your changes.

Detailed solution/guide is not required, but please be sure the challenge is solvable.

Info

Basic info of your challenge questions,

difficulty: hard # medium / hard / extreme
title: key_type from props
tags: object-keys

Question

Implement type that extracts key and type both from object props. More details please refer to test cases.

Template

This is the template for challengers to start the coding. Basically, you just need to change the name of your generic/function and leave to implementation any.

type KeyTypeFromProps<T> = any

Test Cases

Provide some test cases for your challenge, you can use some utils from @type-challenges/utils for asserting.

import type { Equal, Expect } from '@type-challenges/utils'

type obj = {
  [x: string]: (
    | {
      component: 'AInput'
      value: string
    }
    | {
      component: 'ASelect'
      value: string
    }
    | {
      component: 'ARangePicker'
      value: [number, number]
    }
  ) & {
    label?: string
  }
}

type res = {
  AInput: string;
  ASelect: string;
  ARangePicker: [number, number];
}

type cases = [
  Expect<Equal<KeyTypeFromProps<obj, 'component', 'value'>, res>>,

  // @ts-expect-error
  KeyTypeFromProps<{ x: 1 }, '', ''>,
  // @ts-expect-error
  KeyTypeFromProps<obj, 'fake', 'fake'>,
  // @ts-expect-error
  KeyTypeFromProps<[], '', ''>
]
@lvjiaxuan lvjiaxuan added the new-challenge Propose a new challenge, a PR will be auto generated label Dec 20, 2022
@github-actions github-actions bot linked a pull request Dec 20, 2022 that will close this issue
@github-actions
Copy link
Contributor

github-actions bot commented Dec 20, 2022

#20902 - Pull Request updated.

2022-12-20T08:25:44.226Z Preview in Playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-challenge Propose a new challenge, a PR will be auto generated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant