Skip to content

Commit

Permalink
chore: update index
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 4, 2024
1 parent be716f5 commit 130d9d3
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.ja.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.ko.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.pt-BR.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.zh-CN.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions questions/31997-extreme-parameter-intersection/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!--info-header-start--><h1>Parameter Intersection <img src="https://img.shields.io/badge/-extreme-b11b8d" alt="extreme"/> <img src="https://img.shields.io/badge/-%23parameters-999" alt="#parameters"/> <img src="https://img.shields.io/badge/-%23array-999" alt="#array"/> <img src="https://img.shields.io/badge/-%23variadic-999" alt="#variadic"/> <img src="https://img.shields.io/badge/-%23optional-999" alt="#optional"/> <img src="https://img.shields.io/badge/-%23rest-999" alt="#rest"/> <img src="https://img.shields.io/badge/-%23intersection-999" alt="#intersection"/></h1><blockquote><p>by David Blass <a href="https://github.com/ssalbdivad" target="_blank">@ssalbdivad</a></p></blockquote><p><a href="https://tsch.js.org/31997/play" target="_blank"><img src="https://img.shields.io/badge/-Take%20the%20Challenge-3178c6?logo=typescript&logoColor=white" alt="Take the Challenge"/></a> </p><!--info-header-end-->

Given two parameter arrays, compute a third tuple representing the type of args required to satisfy both of the original tuples.

Your solution should correctly handle fixed and non-fixed length arrays, optional elements and variadic elements. For example:
Expand Down Expand Up @@ -27,3 +29,6 @@ type Expected = [
}[]
]
```
<!--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://tsch.js.org/31997/answer" target="_blank"><img src="https://img.shields.io/badge/-Share%20your%20Solutions-teal" alt="Share your Solutions"/></a> <a href="https://tsch.js.org/31997/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 change: 0 additions & 1 deletion questions/31997-extreme-parameter-intersection/info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ tags: parameters, array, variadic, optional, rest, intersection
author:
github: ssalbdivad
name: David Blass

2 changes: 1 addition & 1 deletion questions/31997-extreme-parameter-intersection/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type IntersectParameters<
l extends readonly unknown[],
r extends readonly unknown[]
r extends readonly unknown[],
> = l & r
108 changes: 54 additions & 54 deletions questions/31997-extreme-parameter-intersection/test-cases.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import type { Equal, Expect } from "@type-challenges/utils"
import type { Equal, Expect } from '@type-challenges/utils'

type result1 = IntersectParameters<[], []>
type TwoEmpty = Expect<Equal<[], result1>>

type result2 = IntersectParameters<[], [string, number, ...boolean[]]>
type OneEmpty = Expect<Equal<[string, number, ...boolean[]], result2>>

type result3 = IntersectParameters<["a"], [string, number]>
type LongerParametersPreserved = Expect<Equal<["a", number], result3>>
type result3 = IntersectParameters<['a'], [string, number]>
type LongerParametersPreserved = Expect<Equal<['a', number], result3>>

type result4 = IntersectParameters<[unknown], []>
// Avoids evaluating unknown to {}
type UnknownPreserved = Expect<Equal<[unknown], result4>>

type result5 = IntersectParameters<[("a" | "b" | "c")?], [string, 1 | 2 | 3]>
type OneOptional = Expect<Equal<["a" | "b" | "c", 1 | 2 | 3], result5>>
type result5 = IntersectParameters<[('a' | 'b' | 'c')?], [string, 1 | 2 | 3]>
type OneOptional = Expect<Equal<['a' | 'b' | 'c', 1 | 2 | 3], result5>>

type result6 = IntersectParameters<[{ a: 0 }?], [{ b: 1 }?]>
type BothOptional = Expect<Equal<[{ a: 0; b: 1 }?], result6>>
type BothOptional = Expect<Equal<[{ a: 0, b: 1 }?], result6>>

type result7 = IntersectParameters<[{ a: 0 }?], []>
type OptionalAndNotPresent = Expect<Equal<[{ a: 0 }?], result7>>

type result8 = IntersectParameters<{ a: 0 }[], { b: 1 }[]>
type TwoNonFixedLength = Expect<Equal<{ a: 0; b: 1 }[], result8>>
type TwoNonFixedLength = Expect<Equal<{ a: 0, b: 1 }[], result8>>

type result9 = IntersectParameters<[{ a: 0 }, { b: 1 }], { c: 2 }[]>
type OneNonFixedLength = Expect<
Equal<
[
{
a: 0
c: 2
},
{
b: 1
c: 2
},
...{
c: 2
}[]
{
a: 0
c: 2
},
{
b: 1
c: 2
},
...{
c: 2
}[],
],
result9
>
Expand All @@ -52,17 +52,17 @@ type result10 = IntersectParameters<
type OneTrailingRest = Expect<
Equal<
[
{
a: 0
c: 2
},
{
b: 1
d: 3
},
...{
b: 1
}[]
{
a: 0
c: 2
},
{
b: 1
d: 3
},
...{
b: 1
}[],
],
result10
>
Expand All @@ -75,18 +75,18 @@ type result11 = IntersectParameters<
type TwoTrailingRest = Expect<
Equal<
[
{
a: 0
c: 2
},
{
b: 1
d: 3
},
...{
b: 1
e: 4
}[]
{
a: 0
c: 2
},
{
b: 1
d: 3
},
...{
b: 1
e: 4
}[],
],
result11
>
Expand All @@ -99,28 +99,28 @@ type result12 = IntersectParameters<
type KitchenSink = Expect<
Equal<
[
{
a: 0
e: 4
},
{
a: 0
e: 4
},
{
b: 1
f: 5
b: 1
f: 5
}?,
{
c: 2
g: 6
c: 2
g: 6
}?,
...{
d: 3
g: 6
}[]
d: 3
g: 6
}[],
],
result12
>
>

type result13 = IntersectParameters<["a", "b"], [string, ...string[]]>
type result13 = IntersectParameters<['a', 'b'], [string, ...string[]]>
type ExtraVariadicArgsPreserved = Expect<
Equal<["a", "b", ...string[]], result13>
Equal<['a', 'b', ...string[]], result13>
>

0 comments on commit 130d9d3

Please sign in to comment.