mirror of
https://github.com/type-challenges/type-challenges.git
synced 2026-02-01 15:47:22 +00:00
feat(question): add #34979 - Construct Tuple By Length
This commit is contained in:
parent
c42690e211
commit
e6811109d5
@ -0,0 +1,5 @@
|
||||
Given a generic type `T` and a generic number type `Length extends number`, returns a tuple of type `T` with a length of `Length`.
|
||||
|
||||
```ts
|
||||
type result = ConstructTupleByLength<number, 2>; // [number, number]
|
||||
```
|
||||
@ -0,0 +1,8 @@
|
||||
difficulty: medium
|
||||
title: Construct Tuple By Length
|
||||
tags: tuple, conditional type
|
||||
related: 7544
|
||||
author:
|
||||
github: keepmhwn
|
||||
name: minhwan Kim
|
||||
|
||||
@ -0,0 +1 @@
|
||||
type ConstructTupleByLength<T, Length extends number> = any;
|
||||
@ -0,0 +1,7 @@
|
||||
import type { Equal, Expect } from '@type-challenges/utils'
|
||||
import { ExpectFalse, NotEqual } from '@type-challenges/utils'
|
||||
|
||||
type cases = [
|
||||
Expect<Equal<ConstructTupleByLength<unknown, 0>, []>>,
|
||||
Expect<Equal<ConstructTupleByLength<number | string, 2>, [number | string, number | string]>>,
|
||||
]
|
||||
Loading…
x
Reference in New Issue
Block a user