DEV Community

Ritik Bheda
Ritik Bheda

Posted on

final release 0.4

In the final blog, I am now writing about bringing the code together, testing and PR.

I brought the whole code together, which look like this

import {isEqualType} from 'ts-extras';
const isEqual = isEqualType<ExpectedType, ActualType>();
export type IsEqual<ExpectedType, ActualType> =
    (<T>() => T extends ExpectedType ? 1 : 2) extends
    (<T>() => T extends ActualType ? 1 : 2)
        ? true
        : false;

function assertType<T extends boolean>() {

export function isEqualType<T, G>(): boolean;
export function isEqualType<T, G>(value : G): boolean;
export function isEqualType<T, G>(a: T, b: G){
    return assertType<IsEqual<IsEqual<T, G>, true>>();
Enter fullscreen mode Exit fullscreen mode

now one of the main task was to be done to test and check if our code is working or no.
The project is already using testing framework xo and ava so now I only had to take a look at the testing style in xo and ava and write my test cases.
Finding how to do the test cases was also a bit difficult as I did not have clear idea to what kind of cases to write and compare since there are many types that can be wrote. I then went back to the internet where I can find the way people how other projects were done testing. I tried to get a summary understanding of it started implementing it and after a few additions and subtraction, I came up with my test cases and was ready to test. Well of the cases do pass and covers a broad spectrum of possible cases, but I doubt I might have missed special cases. The good thing is it covers over 99% cases but I am looking forward to search for that 1% of case I have missed.

The test cases look like this:

import test from 'ava';
import {isEqualType} from '../source/index.js';

test('isEqual()', t => {

    t.true(isEqualType<1, 1>());
    t.true(isEqualType<any, any>());
    t.true(isEqualType<unknown, unknown>());

    t.false(isEqualType<{}, {x:1}>());
    t.false(isEqualType<1, 2>());
    t.false(isEqualType<1, any>());
    t.false(isEqualType<1, unknown>());
    t.false(isEqualType<any, unknown>());

Enter fullscreen mode Exit fullscreen mode

I then updated the readme page and push my commits and created a PR

Top comments (0)