Skip to content

Commit

Permalink
feat(question): add #20901 - key_type from props
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Dec 20, 2022
1 parent d535735 commit 3047da3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions questions/20901-hard-key_type-from-props/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement type that extracts key and type both from object props. More details please refer to test cases.
7 changes: 7 additions & 0 deletions questions/20901-hard-key_type-from-props/info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
difficulty: hard
title: key_type from props
tags: object-keys
author:
github: lvjiaxuan
name: lvjiaxuan

1 change: 1 addition & 0 deletions questions/20901-hard-key_type-from-props/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type KeyTypeFromProps<T> = any
37 changes: 37 additions & 0 deletions questions/20901-hard-key_type-from-props/test-cases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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<[], '', ''>
]

0 comments on commit 3047da3

Please sign in to comment.