-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(question): add #20901 - key_type from props
- Loading branch information
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
difficulty: medium | ||
title: key_type from props | ||
tags: object-keys | ||
author: | ||
github: lvjiaxuan | ||
name: lvjiaxuan | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type KeyTypeFromProps<T> = any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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>>, | ||
] |