-
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(types): init v0.0.12 * fix(types): Remove duplicated tests (#5) * feat(types): ArrayOfN type now accepts any type as Fill (#6) * Feat(types): Add equal type and derivatives (#7) * feat(types): Added the Box helper type * feat(types): Added the Equal type * feat(types): Added the LessThanEqual derived type * chore(types): Exposed the Box, Equal, and LessThanEqual types * chore(types): added patch notes * chore(*): Updated versions
- Loading branch information
Showing
19 changed files
with
231 additions
and
32 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": "@ylfjuk/md" | ||
"extends": "@ylfjuk/md", | ||
"MD013": { | ||
"line_length": 120 | ||
} | ||
} |
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
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
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 @@ | ||
export type Box<T> = { _: T }; |
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,11 @@ | ||
import type { Box } from './box'; | ||
|
||
/** | ||
* @alternative | ||
* type Equal<A, B> = (<G>() => G extends A ? 1 : 2) extends (<G>() => G extends B ? 1 : 2) ? true : false | ||
*/ | ||
export type Equal<A, B> = Box<A> extends Box<B> | ||
? Box<B> extends Box<A> | ||
? true | ||
: false | ||
: false; |
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
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,15 @@ | ||
import type { Equal } from './equal'; | ||
import type { LessThan } from './less-than'; | ||
|
||
/** | ||
* @description | ||
* A, B ∈ ℤ (integers) | ||
* | ||
* @note does not support float values | ||
*/ | ||
export type LessThanEqual<A extends number, B extends number> = Equal< | ||
A, | ||
B | ||
> extends true | ||
? true | ||
: LessThan<A, B>; |
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,17 @@ | ||
import { describe, expectTypeOf, it } from 'vitest'; | ||
import type { InverseExtract } from '../src'; | ||
import type { Box } from './../src/box'; | ||
|
||
describe('A type to Box union types', () => { | ||
it('should match full unions instead of testing each element separately', () => { | ||
type UnionIsTestedSeparately = InverseExtract<string | number, string>; | ||
|
||
type Actual = InverseExtract<Box<string | number>, Box<string>>; | ||
|
||
type Expected = never; | ||
|
||
expectTypeOf<UnionIsTestedSeparately>().toEqualTypeOf<string>(); | ||
expectTypeOf<UnionIsTestedSeparately>().not.toEqualTypeOf<Expected>(); | ||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
}); |
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,39 @@ | ||
import { describe, expectTypeOf, test } from 'vitest'; | ||
import type { Equal } from './../src/equal'; | ||
|
||
describe('A type that checks if two other types are strictly equal', () => { | ||
test('diff types', () => { | ||
type Actual = Equal<string, number>; | ||
type Expected = false; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
|
||
test('same types', () => { | ||
type Actual = Equal<number, number>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
|
||
test('same literals', () => { | ||
type Actual = Equal<2, 2>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
|
||
test('literals and mask', () => { | ||
type Actual = Equal<2, number>; | ||
type Expected = false; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
|
||
test('type and union with it', () => { | ||
type Actual = Equal<string | number, number>; | ||
type Expected = false; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
}); |
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,97 @@ | ||
import { describe, expectTypeOf, test } from 'vitest'; | ||
import type { LessThanEqual } from '../src/less-than-equal'; | ||
|
||
describe('returns if a number is less than another number', () => { | ||
test('+x < +y', () => { | ||
type Actual = LessThanEqual<1, 2>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('+x = +y', () => { | ||
type Actual = LessThanEqual<1, 1>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('+x > +y', () => { | ||
type Actual = LessThanEqual<2, 1>; | ||
type Expected = false; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('+x > 0', () => { | ||
type Actual = LessThanEqual<1, 0>; | ||
type Expected = false; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('0 < +y', () => { | ||
type Actual = LessThanEqual<0, 1>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('0 = 0', () => { | ||
type Actual = LessThanEqual<0, 0>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('-x < +y', () => { | ||
type Actual = LessThanEqual<-3, 3>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('+x > -y', () => { | ||
type Actual = LessThanEqual<3, -2>; | ||
type Expected = false; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('-x = -y', () => { | ||
type Actual = LessThanEqual<-2, -2>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('-x < -y', () => { | ||
type Actual = LessThanEqual<-3, -2>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('-x > -y', () => { | ||
type Actual = LessThanEqual<-2, -3>; | ||
type Expected = false; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('-x < 0', () => { | ||
type Actual = LessThanEqual<-3, 0>; | ||
type Expected = true; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test('0 > -y', () => { | ||
type Actual = LessThanEqual<0, -3>; | ||
type Expected = false; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>; | ||
}); | ||
|
||
test.todo('add float support'); | ||
}); |
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
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 |
---|---|---|
|
@@ -12,6 +12,6 @@ | |
"vite": "^6.0.3" | ||
}, | ||
"dependencies": { | ||
"@ylfjuk/core": "^0.0.12" | ||
"@ylfjuk/core": "^0.0.13" | ||
} | ||
} |