Back to Type Challenges

README

questions/31997-extreme-parameter-intersection/README.md

latest1.9 KB
Original Source
<!--info-header-start--><h1>Parameter 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"></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:

ts
type Result = IntersectParameters<
	[{ a: 0 }, { b: 1 }?, { c: 2 }?, ...{ d: 3 }[]],
	[{ e: 4 }?, { f: 5 }?, ...{ g: 6 }[]]
>

type Expected = [
	{
		a: 0
		e: 4
	},
	{
		b: 1
		f: 5
	}?,
	{
		c: 2
		g: 6
	}?,
	...{
		d: 3
		g: 6
	}[]
]
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/31997/answer" target="_blank"></a> <a href="https://tsch.js.org/31997/solutions" target="_blank"></a> <!--info-footer-end-->