Skip to content

Commit

Permalink
feat(question): add #29572 - ObjectValues
Browse files Browse the repository at this point in the history
  • Loading branch information
yrui-ql committed Aug 17, 2023
1 parent 194e6f0 commit 7046715
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions questions/29572-hard-objectvalues/README.zh-CN.md
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]
```
6 changes: 6 additions & 0 deletions questions/29572-hard-objectvalues/info.zh-CN.yml
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

1 change: 1 addition & 0 deletions questions/29572-hard-objectvalues/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type ObjectValues = any[]
15 changes: 15 additions & 0 deletions questions/29572-hard-objectvalues/test-cases.ts
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)
]

0 comments on commit 7046715

Please sign in to comment.