Skip to content

Commit

Permalink
feature: Add rtt plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Dec 4, 2023
1 parent 7b3350f commit f5ef8d9
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 204 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "rtt-plugin"]
path = rtt-plugin
url = https://github.com/Eythaann/rtt-plugin
2 changes: 0 additions & 2 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run build:plugin

echo "Running type checking on min supported version...\n"
npx -p [email protected] tsc --incremental --noEmit

Expand Down
2 changes: 1 addition & 1 deletion lib/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IValidations, TestsCallback } from './readable-test-types';

declare global {
function describeType(description: string, cb: () => void): void;
function testType(description: string, tests: anyObject | TestsCallback): void;
function testType(description: string, tests: TestsCallback): void;
function assertType<T>(): IValidations<T>;

interface RT_CONFIG {}
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/conditions/infrastructure.spec-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describeType('If', () => {
});

testType('Should return false case', () => {
assertType<ExplicitCondition<{ condition: false; then: string; else: number }>>().equals<string>();
assertType<ExplicitCondition<{ condition: false; then: string; else: number }>>().equals<number>();
assertType<ExplicitCondition<{ condition: never; then: string; else: number }>>().equals<number>();
});
});
});
26 changes: 11 additions & 15 deletions lib/modules/objects/infrastructure.spec-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describeType('IsStrictObject', () => {
});

describeType('Modify', () => {
testType('Should modify the object', (validator) => {
testType('Should modify the object', () => {
type Base = {
prop1: string;
prop2: number;
Expand All @@ -62,11 +62,9 @@ describeType('Modify', () => {
newProp: boolean;
};

validator([
assertType<modify<Base, { newProp: never }>>().not.equals<Base>(),
assertType<modify<Base, { newProp: boolean }>>().equals<expected>(),
assertType<modify<Base, { newProp1: boolean }>>().toHaveProperty('newProp1'),
]);
assertType<modify<Base, { newProp: never }>>().not.equals<Base>();
assertType<modify<Base, { newProp: boolean }>>().equals<expected>();
assertType<modify<Base, { newProp1: boolean }>>().toHaveProperty('newProp1');
});
});

Expand All @@ -77,21 +75,19 @@ describeType('Prettify', () => {
});

describeType('PickByValue', () => {
testType('Should pick properties whose value types match any in the ValuesToPick array', (validator) => {
testType('Should pick properties whose value types match any in the ValuesToPick array', () => {
type T1 = { a: string; b: number; c: string | number };
type T2 = { d: boolean; e: null; f: undefined; g: any; h: never };
type T3 = { i: { j: string }; k: [number, string] };
type T4 = { l: symbol; m: bigint };
type T5 = {};

validator([
assertType<pickByValue<T1, [string, number]>>().equals<{ a: string; b: number }>(),
assertType<pickByValue<T1, [string | number]>>().equals<{ c: string | number }>(),
assertType<pickByValue<T2, [boolean, null, undefined, any, never]>>().equals<{ d: boolean; e: null; f: undefined; g: any; h: never }>(),
assertType<pickByValue<T3, [{ j: string }, [number, string]]>>().equals<{ i: { j: string }; k: [number, string] }>(),
assertType<pickByValue<T4, [symbol, bigint]>>().equals<{ l: symbol; m: bigint }>(),
assertType<pickByValue<T5, [string]>>().equals<{}>(),
]);
assertType<pickByValue<T1, [string, number]>>().equals<{ a: string; b: number }>();
assertType<pickByValue<T1, [string | number]>>().equals<{ c: string | number }>();
assertType<pickByValue<T2, [boolean, null, undefined, any, never]>>().equals<{ d: boolean; e: null; f: undefined; g: any; h: never }>();
assertType<pickByValue<T3, [{ j: string }, [number, string]]>>().equals<{ i: { j: string }; k: [number, string] }>();
assertType<pickByValue<T4, [symbol, bigint]>>().equals<{ l: symbol; m: bigint }>();
assertType<pickByValue<T5, [string]>>().equals<{}>();
});
});

Expand Down
18 changes: 9 additions & 9 deletions lib/modules/unknow/infrastructure.spec-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ describeType('IsUnknown', () => {
assertType<isUnknown<never>>().toBeFalse(),
assertType<isUnknown<unknown & string>>().toBeFalse(),
]);
});

describeType('DefaultOnUnknown', () => {
testType('Should replace unknown type with the default type', () => {
type result = defaultOnUnknown<unknown, string>;
assertType<result>().equals<string>();
});
describeType('DefaultOnUnknown', () => {
testType('Should replace unknown type with the default type', () => {
type result = defaultOnUnknown<unknown, string>;
assertType<result>().equals<string>();
});

testType('Should retain the original type if it is known', () => {
type result = defaultOnUnknown<number, string>;
assertType<result>().equals<number>();
});
testType('Should retain the original type if it is known', () => {
type result = defaultOnUnknown<number, string>;
assertType<result>().equals<number>();
});
});
2 changes: 1 addition & 1 deletion lib/readable-test-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ export type IValidations<T> = isTrue<forceExtract<RT_CONFIG, 'development'>> ext
? IValidationsInternal<T>
: IValidationsPublic<T>;

export type TestsCallback = (validator: (asserts: anyObject) => void) => anyObject | void;
export type TestsCallback = (() => void) | anyObject;
46 changes: 27 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
"types": "./lib/index.d.ts",
"main": "./lib/plugins/dist/index.js",
"scripts": {
"build:plugin": "tsc -p ./plugins",
"typeChecking": "tsc -p ./",
"typeChecking": "tsc",
"test": "rtt",
"debugTypes": "tsc --generateTrace ./outDir",
"lint": "eslint \"./lib/**/*.{ts,tsx}\" --max-warnings 0",
"lint:fix": "eslint \"./lib/**/*.{ts,tsx}\" --max-warnings 0 --fix",
"prepare": "husky install",
"postversion": "git push && git push --tags --no-verify && npm publish",
"prepublish": "tsc -p ./plugins"
"postversion": "git push && git push --tags --no-verify && npm publish"
},
"repository": {
"type": "git",
Expand All @@ -36,7 +35,7 @@
"url": "https://github.com/Eythaann/readable-types/issues"
},
"dependencies": {
"readable-types-plugin": "file:./plugins",
"readable-types-plugin": "file:./rtt-plugin",
"typescript": "^4.8"
},
"devDependencies": {
Expand Down
58 changes: 0 additions & 58 deletions plugins/dist/index.js

This file was deleted.

1 change: 0 additions & 1 deletion plugins/dist/index.js.map

This file was deleted.

5 changes: 0 additions & 5 deletions plugins/package.json

This file was deleted.

Loading

0 comments on commit f5ef8d9

Please sign in to comment.