-
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.
feat: ✨ Add the Length type - Check a given types length
- Loading branch information
1 parent
33c7a46
commit a1ca1ff
Showing
3 changed files
with
27 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,5 @@ | ||
--- | ||
"@crbroughton/ts-test-utils": minor | ||
--- | ||
|
||
Add the Length type - Check a given types length |
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
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,20 @@ | ||
/* eslint-disable unused-imports/no-unused-vars */ | ||
import { describe, it } from 'bun:test' | ||
import type { Equals, Expect, Length } from '../index' | ||
|
||
describe('Length tests', () => { | ||
it('Passes the length test when the lengths dont match', () => { | ||
type Result = Expect<Equals<Length<[0, 1, 2]>, 3>> | ||
// ^? | ||
type ResultRecord = Expect<Equals<Length<[{ id: string }, { name: string }]>, 2>> | ||
// ^? | ||
}) | ||
it('Fails the length test when the types are not of the same length', () => { | ||
// @ts-expect-error - number values failing the length checker | ||
type Results = Expect<Equals<Length<[0, 1, 2]>, 10>> | ||
// ^? | ||
// @ts-expect-error - Object / Record failing the length checker | ||
type ResultRecord = Expect<Equals<Length<[{ id: string }, { name: string }]>, 10>> | ||
// ^? | ||
}) | ||
}) |