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

新题目 #29572

Open
yrui-ql opened this issue Aug 17, 2023 · 3 comments · May be fixed by #29573
Open

新题目 #29572

yrui-ql opened this issue Aug 17, 2023 · 3 comments · May be fixed by #29573
Labels
new-challenge Propose a new challenge, a PR will be auto generated zh-CN 简体中文

Comments

@yrui-ql
Copy link

yrui-ql commented Aug 17, 2023

基本信息

# 题目难度
difficulty: hard 

# 题目标题
title: ObjectValues

# 题目标签
# tags: union, array, object

题目

Implement a type, ObjectValues, just like Object.values

it looks like this

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]

题目模版

type ObjectValues = any[]

判题测试

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)
]
@yrui-ql yrui-ql added new-challenge Propose a new challenge, a PR will be auto generated zh-CN 简体中文 labels Aug 17, 2023
@github-actions github-actions bot linked a pull request Aug 17, 2023 that will close this issue
@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2023

#29573 - PR 已更新

2023-08-17T07:52:57.583Z 在 Playground 中预览

github-actions bot pushed a commit that referenced this issue Aug 17, 2023
github-actions bot pushed a commit that referenced this issue Aug 17, 2023
@jiangshanmeta
Copy link
Member

Actually, for union type , the order doesn't matter. "a" | "b" is totally the same with "b" | "a"
Based on that, how could you expect an ordered result, as there is order in tuple.

联合类型是没有顺序的,就像一个集合。
但是元素是有顺序的。
所以我们期望得到的应该是联合类型而不是tuple

题目中的那个TODO也是这个原因做不出来

@JokerDr 有啥想法?

@yrui-ql
Copy link
Author

yrui-ql commented Aug 20, 2023

Actually, for union type , the order doesn't matter. "a" | "b" is totally the same with "b" | "a" Based on that, how could you expect an ordered result, as there is order in tuple.

联合类型是没有顺序的,就像一个集合。 但是元素是有顺序的。 所以我们期望得到的应该是联合类型而不是tuple

题目中的那个TODO也是这个原因做不出来

@JokerDr 有啥想法?

确实是这样,我自己也只是实现了除TODO外的其他的case。也许确实如你所说, 那是不可能的,或许换成['a','b','c']这种应该是可以的

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 zh-CN 简体中文
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants