Skip to content

Commit

Permalink
feature: Add isAssignableTo test alias
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Dec 4, 2023
1 parent f5ef8d9 commit 11776b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/modules/generals/infrastructure.spec-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ describeType('Opaque', () => {

testType('Should not be asignable to its baseType', () => {
type UserID = Opaque<number, 'UserID'>;
assertType<UserID>().not.isSubTypeOf<number>();
assertType<UserID>().not.isAssignableTo<number>();
});

testType('Should its baseType not asignable to Opaque', () => {
type UserID = Opaque<number, 'UserID'>;
assertType<UserID>().not.isSuperTypeOf<number>();
assertType<number>().not.isAssignableTo<UserID>();
});

testType('Should differentiate between different opaque types', () => {
Expand All @@ -81,12 +81,12 @@ describeType('WeakOpaque', () => {

testType('Should be asignable to its baseType', () => {
type UserID = WeakOpaque<number, 'UserID'>;
assertType<UserID>().isSubTypeOf<number>();
assertType<UserID>().isAssignableTo<number>();
});

testType('Should its baseType not asignable to Opaque', () => {
type UserID = WeakOpaque<number, 'UserID'>;
assertType<UserID>().not.isSuperTypeOf<number>();
assertType<number>().not.isAssignableTo<UserID>();
});

testType('Should differentiate between different opaque types', () => {
Expand Down
3 changes: 3 additions & 0 deletions lib/readable-test-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ interface IValidationsPublic<T, I extends boolean = false> {
/** expected type should be extended of asserting type*/
isSuperTypeOf: <U>() => NotIf<I, isSupertype<T, U>> extends true ? RTT_PASS : RTT_FAIL<FailMsgs<I>['supertype']>;

/** expected type should be extended of asserting type*/
isAssignableTo: <U>() => NotIf<I, isSubtype<T, U>> extends true ? RTT_PASS : RTT_FAIL<FailMsgs<I>['subtype']>;

/** asserting type should be extended of expected type */
isSubTypeOf: <U>() => NotIf<I, isSubtype<T, U>> extends true ? RTT_PASS : RTT_FAIL<FailMsgs<I>['subtype']>;

Expand Down
1 change: 1 addition & 0 deletions lib/readable-test-types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ globalThis.assertType = () => ({
returned: globalThis.assertType,
equals() {},
isSuperTypeOf() {},
isAssignableTo() {},
isSubTypeOf() {},
toBeTrue() {},
toBeFalse() {},
Expand Down

0 comments on commit 11776b7

Please sign in to comment.