mirror of
https://github.com/type-challenges/type-challenges.git
synced 2026-02-01 15:47:22 +00:00
Merge branch 'master' of https://github.com/type-challenges/type-challenges
This commit is contained in:
commit
36f6e66067
@ -5,11 +5,11 @@ For given a tuple, you need create a generic `Length`, pick the length of the tu
|
||||
For example
|
||||
|
||||
```ts
|
||||
type tesla = ['tesla', 'model 3', 'model X', 'model Y']
|
||||
type spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT']
|
||||
type tesla = ['tesla', 'model 3', 'model X', 'model Y'] as const
|
||||
type spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT'] as const
|
||||
|
||||
type teslaLength = Length<tesla> // expected 4
|
||||
type spaceXLength = Length<spaceX> // expected 5
|
||||
type teslaLength = Length<typeof tesla> // expected 4
|
||||
type spaceXLength = Length<typeof spaceX> // expected 5
|
||||
```
|
||||
|
||||
<!--info-footer-start--><br><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/18/answer" target="_blank"><img src="https://img.shields.io/badge/-Share%20your%20Solutions-teal" alt="Share your Solutions"/></a> <a href="https://type-challenges.netlify.app/18/solutions" target="_blank"><img src="https://img.shields.io/badge/-Check%20out%20Solutions-de5a77?logo=awesome-lists&logoColor=white" alt="Check out Solutions"/></a> <!--info-footer-end-->
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { Equal, Expect } from '@type-challenges/utils'
|
||||
|
||||
const tesla = ['tesla', 'model 3', 'model X', 'model Y']
|
||||
const spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT']
|
||||
const tesla = ['tesla', 'model 3', 'model X', 'model Y'] as const
|
||||
const spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT'] as const
|
||||
|
||||
type cases = [
|
||||
Expect<Equal<Length<tesla>, 4>>,
|
||||
Expect<Equal<Length<spaceX>, 5>>,
|
||||
Expect<Equal<Length<typeof tesla>, 4>>,
|
||||
Expect<Equal<Length<typeof spaceX>, 5>>,
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user