mirror of
https://github.com/type-challenges/type-challenges.git
synced 2025-12-08 19:06:13 +00:00
feat: tuple-to-union
This commit is contained in:
parent
378a6f56c4
commit
ccf901b505
13
questions/10-medium-tuple-to-union/README.md
Normal file
13
questions/10-medium-tuple-to-union/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
<!--info-header-start--><h1>Deep Readonly <img src="https://img.shields.io/badge/-medium-eaa648" alt="medium"/> <img src="https://img.shields.io/badge/-%23readonly-999" alt="#readonly"/> <img src="https://img.shields.io/badge/-%23object--keys-999" alt="#object-keys"/> <img src="https://img.shields.io/badge/-%23deep-999" alt="#deep"/></h1><blockquote><p>by Anthony Fu <a href="https://github.com/antfu" target="_blank">@antfu</a></p></blockquote><a href="https://type-challenges.netlify.app/case/9/play" target="_blank"><img src="https://img.shields.io/badge/-Take%20the%20Challenge-3178c6?logo=typescript" alt="Take the Challenge"/></a> <br><br><!--info-header-end-->
|
||||
|
||||
Implement a generic `TupleToUnion<T>` which covers the values of a tuple to its values union.
|
||||
|
||||
For example
|
||||
|
||||
```ts
|
||||
type Arr = ['1', '2', '3']
|
||||
|
||||
const a: TupleToUnion<X> // expected to be '1' | '2' | '3'
|
||||
```
|
||||
|
||||
<!--info-footer-start--><a href="../../README.md" target="_blank"><img src="https://img.shields.io/badge/-Back-grey" alt="Back"/></a> <a href="https://type-challenges.netlify.app/case/9/solutions" target="_blank"><img src="https://img.shields.io/badge/-Check%20out%20Solutions-de5a77?logo=awesome-lists&logoColor=white" alt="Check out Solutions"/></a> <a href="https://type-challenges.netlify.app/case/9/answer" target="_blank"><img src="https://img.shields.io/badge/-Share%20your%20Solutions-green" alt="Share your Solutions"/></a> <!--info-footer-end-->
|
||||
8
questions/10-medium-tuple-to-union/info.yml
Normal file
8
questions/10-medium-tuple-to-union/info.yml
Normal file
@ -0,0 +1,8 @@
|
||||
title: Tuple to Union
|
||||
|
||||
author:
|
||||
name: Anthony Fu
|
||||
email: hi@antfu.me
|
||||
github: antfu
|
||||
|
||||
tags: infer, tuple, union
|
||||
1
questions/10-medium-tuple-to-union/info.zh-CN.yml
Normal file
1
questions/10-medium-tuple-to-union/info.zh-CN.yml
Normal file
@ -0,0 +1 @@
|
||||
title: 元组转合集
|
||||
1
questions/10-medium-tuple-to-union/template.ts
Normal file
1
questions/10-medium-tuple-to-union/template.ts
Normal file
@ -0,0 +1 @@
|
||||
type TupleToUnion<T> = any
|
||||
6
questions/10-medium-tuple-to-union/test-cases.ts
Normal file
6
questions/10-medium-tuple-to-union/test-cases.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { Equal, Expect } from '@type-challenges/utils'
|
||||
|
||||
type cases = [
|
||||
Expect<Equal<TupleToUnion<[123, '456', true]>, 123 | '456' | true>>,
|
||||
Expect<Equal<TupleToUnion<[123]>, 123>>,
|
||||
]
|
||||
Loading…
x
Reference in New Issue
Block a user