-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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 #29572 - ObjectValues
- Loading branch information
Showing
4 changed files
with
40 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,18 @@ | ||
Implement a type, `ObjectValues`, just like `Object.values` | ||
|
||
it looks like this | ||
```ts | ||
interface TestCase1 { | ||
a: number; | ||
b: string; | ||
c: 'this is c'; | ||
d: () => void; | ||
} | ||
|
||
ObjectValues<TestCase1> ;//[number, string,'this is c', () => void] | ||
ObjectValues<TestCase1,'a'|'b'|'d'> ;// [number, string, () => void] | ||
|
||
//TODO | ||
// In fact,I hope it can be like this. However, I did not realize this idea, if you are interested, you can give it a try | ||
ObjectValues<TestCase1,"d"|"a"> ;// by type order [() => void, number] | ||
``` |
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,6 @@ | ||
difficulty: hard | ||
title: ObjectValues | ||
author: | ||
github: JokerDr | ||
name: a_flappy_fish | ||
|
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 ObjectValues = 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,15 @@ | ||
import type { Equal, Expect } from '@type-challenges/utils' | ||
import { ExpectFalse, NotEqual } from '@type-challenges/utils' | ||
|
||
interface TestCase1 { | ||
a: number; | ||
b: string; | ||
c: 'this is c'; | ||
d: () => void; | ||
} | ||
|
||
type cases = [ | ||
Expect<Equal<ObjectValues<TestCase1> , [number, string,'this is c', () => void]>>, | ||
Expect<Equal<ObjectValues<TestCase1,'a'|'b'|'d'> , [number, string, () => void]>>, | ||
Expect<Equal<ObjectValues<TestCase1,"d"|"a"> ,[() => void, number]>>,// Add a little more difficulty (optional) | ||
] |