Skip to content

Commit

Permalink
[Foundation] Upgrade ts version to 4.9.5 and rest to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Bao committed Apr 7, 2023
1 parent b65a674 commit 40cc52d
Show file tree
Hide file tree
Showing 6 changed files with 1,343 additions and 939 deletions.
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"name": "power-guard",
"version": "1.0.8",
"name": "@scdt-china/power-guard",
"version": "3.0.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib"
],
"repository": "https://github.com/gao-sun/power-guard",
"author": "Gao Sun",
"license": "MIT",
"type": "module",
"repository": "[email protected]:scdt-china/power-guard.git",
"scripts": {
"build": "rm -rf lib/ && tsc",
"lint": "eslint --ext .tsx --ext .ts src/ tests/",
"test": "nyc --reporter=html mocha -r ts-node/register tests/**/*.test.ts"
},
"devDependencies": {
"@types/chai": "^4.2.12",
"@types/mocha": "^8.0.1",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"chai": "^4.2.0",
"eslint": "^7.5.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.1.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"chai": "^4.3.7",
"eslint": "^8.37.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^8.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
"prettier": "^2.8.7",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
}
}
6 changes: 3 additions & 3 deletions src/enum/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { isEnum } from '../types';
import { Optional } from '../global';
import PowerGuardError from '../error';

function guard<T>(enumObject: T, x: unknown): T[keyof T];
function guard<T>(enumObject: T, x: unknown, optional: true): Optional<T[keyof T]>;
function guard<T>(enumObject: T, x: unknown, optional = false): Optional<T[keyof T]> {
function guard<T extends Record<string, unknown>>(enumObject: T, x: unknown): T[keyof T];
function guard<T extends Record<string, unknown>>(enumObject: T, x: unknown, optional: true): Optional<T[keyof T]>;
function guard<T extends Record<string, unknown>>(enumObject: T, x: unknown, optional = false): Optional<T[keyof T]> {
if (isEnum(enumObject)(x)) {
return x;
}
Expand Down
4 changes: 2 additions & 2 deletions src/enum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { GuardClass, GuardFunctionWithArray, OptionalGuardFunctionWithArray } fr

type EnumType<T> = T[keyof T];

class EnumGuard<T> implements GuardClass<EnumType<T>> {
static create<T>(enumObject: T) {
class EnumGuard<T extends Record<string, unknown>> implements GuardClass<EnumType<T>> {
static create<T extends Record<string, unknown>>(enumObject: T) {
return new EnumGuard(enumObject);
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const isNull = (x: unknown): x is null => x === null;

export const isObject = (x: unknown): x is object => !isNull(x) && typeof x === 'object';

export const isEnum = <T>(enumObject: T) => (token: unknown): token is T[keyof T] =>
export const isEnum = <T extends Record<string, unknown>>(enumObject: T) => (token: unknown): token is T[keyof T] =>
Object.values(enumObject).includes(token as T[keyof T]);

export const isArray = <T>(elemGuard: Guard<T>) => (x: unknown): x is Array<T> =>
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
Expand Down
Loading

0 comments on commit 40cc52d

Please sign in to comment.