-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
- Loading branch information
1 parent
d14adf9
commit dd0493d
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Equal, Expect } from "type-testing"; | ||
|
||
/* ----------------------------------------------------------------------------------------------- | ||
* Code Here | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
type BoxToys<S, N, Arr extends S[] = []> = | ||
// Arr["length"] extends N // this doesn't work w/ union types | ||
N extends Arr["length"] // works | ||
? Arr | ||
: BoxToys<S, N, [...Arr, S]>; | ||
|
||
/* ----------------------------------------------------------------------------------------------- | ||
* Do Not Edit Below This Line | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
type test_doll_actual = BoxToys<"doll", 1>; | ||
// ^? | ||
type test_doll_expected = ["doll"]; | ||
type test_doll = Expect<Equal<test_doll_expected, test_doll_actual>>; | ||
|
||
type test_nutcracker_actual = BoxToys<"nutcracker", 3 | 4>; | ||
// ^? | ||
type test_nutcracker_expected = | ||
| ["nutcracker", "nutcracker", "nutcracker"] | ||
| ["nutcracker", "nutcracker", "nutcracker", "nutcracker"]; | ||
type test_nutcracker = Expect< | ||
Equal<test_nutcracker_expected, test_nutcracker_actual> | ||
>; |