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

新题目 #9535

Open
Laffery opened this issue Apr 30, 2022 · 5 comments · May be fixed by #9536
Open

新题目 #9535

Laffery opened this issue Apr 30, 2022 · 5 comments · May be fixed by #9536
Labels
new-challenge Propose a new challenge, a PR will be auto generated zh-CN 简体中文

Comments

@Laffery
Copy link

Laffery commented Apr 30, 2022

请按照以下的模版填充相应的内容,一个 PR 会自动生成并保持与本 Issue 的内容同步。

你不需要提供详细的答案或教学,但请保证题目可解。

基本信息

# 题目难度
difficulty: medium

# 题目标题
title: void function

# 题目标签
# tags: array, function

题目

默认的VoidFunction不支持范型,现在请实现一个支持范型的VoidFunction类型

VoidFunction // () => void
VoidFunction<boolean> // (arg: boolean) => void
VoidFunction<[boolean, boolean]> // (...args: [boolean, boolean]) => void

题目模版

以下是给予挑战者开始做题的代码模版,在大部分情况下你只需要修改类型名称使其符合你的题目与判题测试,实现的部分保持 any 即可。

type VoidFunction<T> = any

判题测试

请为你的题目提供一些判题测试,你可以使用 @type-challenges/utils 中提供的一些工具进行判断。

import type { Equal, Expect } from '@type-challenges/utils'
import { ExpectFalse, NotEqual } from '@type-challenges/utils'

type cases = [
  Expect<Equal<VoidFunction, () => void>>,
  Expect<Equal<VoidFunction<boolean>, (arg: boolean) => void>>,
  Expect<Equal<VoidFunction<[boolean, boolean]>, (arg1: boolean, arg2: boolean) => void>>,
  Expect<Equal<VoidFunction<[boolean, boolean, boolean]>, (...args: [boolean, boolean, boolean]) => void>>,
]
@Laffery Laffery added new-challenge Propose a new challenge, a PR will be auto generated zh-CN 简体中文 labels Apr 30, 2022
github-actions bot pushed a commit that referenced this issue Apr 30, 2022
@github-actions github-actions bot linked a pull request Apr 30, 2022 that will close this issue
@github-actions
Copy link
Contributor

#9536 - PR 已更新

2022-04-30T07:13:08.746Z 在 Playground 中预览

@Nauxscript
Copy link
Contributor

// 我的答案
type VoidFunction<T = never> = [T] extends [never] ?  () => void : [T] extends  [unknown[]] ? (...arg: T) => void : (arg: T) => void

@jiangshanmeta
Copy link
Member

type MakeArr<T,U = T> = T extends any[]? T:[U];
type VoidFunction<T = []> = (...args:MakeArr<T>)=>void;

@Laffery
Copy link
Author

Laffery commented Dec 13, 2022

// 我的答案
type VoidFunction<T = never> = [T] extends [never] ?  () => void : [T] extends  [unknown[]] ? (...arg: T) => void : (arg: T) => void

LGTM! But if there is some difference in the 2nd case: boolean to be boolean[], it seems that the answer doesn't work.

@Laffery
Copy link
Author

Laffery commented Dec 13, 2022

LGTM! But if there is some difference in the 2nd case: boolean to be boolean[], it seems that the answer doesn't work.

LGTM! But if there is some difference in the 2nd case: boolean to be boolean[], it seems that the answer doesn't work.

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.

3 participants