Skip to content

Commit 40cc52d

Browse files
author
Bo Bao
committed
[Foundation] Upgrade ts version to 4.9.5 and rest to latest
1 parent b65a674 commit 40cc52d

6 files changed

Lines changed: 1343 additions & 939 deletions

File tree

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
{
2-
"name": "power-guard",
3-
"version": "1.0.8",
2+
"name": "@scdt-china/power-guard",
3+
"version": "3.0.0",
44
"main": "lib/index.js",
55
"types": "lib/index.d.ts",
66
"files": [
77
"lib"
88
],
9-
"repository": "https://github.com/gao-sun/power-guard",
109
"author": "Gao Sun",
1110
"license": "MIT",
11+
"type": "module",
12+
"repository": "git@github.com:scdt-china/power-guard.git",
1213
"scripts": {
1314
"build": "rm -rf lib/ && tsc",
1415
"lint": "eslint --ext .tsx --ext .ts src/ tests/",
1516
"test": "nyc --reporter=html mocha -r ts-node/register tests/**/*.test.ts"
1617
},
1718
"devDependencies": {
18-
"@types/chai": "^4.2.12",
19-
"@types/mocha": "^8.0.1",
20-
"@typescript-eslint/eslint-plugin": "^3.6.1",
21-
"@typescript-eslint/parser": "^3.6.1",
22-
"chai": "^4.2.0",
23-
"eslint": "^7.5.0",
24-
"eslint-config-prettier": "^6.11.0",
25-
"eslint-config-standard": "^14.1.1",
26-
"eslint-plugin-import": "^2.22.0",
19+
"@types/chai": "^4.3.0",
20+
"@types/mocha": "^9.1.0",
21+
"@typescript-eslint/eslint-plugin": "^5.57.1",
22+
"@typescript-eslint/parser": "^5.57.1",
23+
"chai": "^4.3.7",
24+
"eslint": "^8.37.0",
25+
"eslint-config-prettier": "^8.8.0",
26+
"eslint-config-standard": "^17.0.0",
27+
"eslint-plugin-import": "^2.27.5",
2728
"eslint-plugin-node": "^11.1.0",
28-
"eslint-plugin-prettier": "^3.1.4",
29-
"eslint-plugin-promise": "^4.2.1",
30-
"eslint-plugin-standard": "^4.0.1",
31-
"mocha": "^8.1.0",
29+
"eslint-plugin-prettier": "^4.2.1",
30+
"eslint-plugin-promise": "^6.1.1",
31+
"mocha": "^10.2.0",
3232
"nyc": "^15.1.0",
33-
"prettier": "^2.0.5",
34-
"ts-node": "^8.10.2",
35-
"typescript": "^3.9.7"
33+
"prettier": "^2.8.7",
34+
"ts-node": "^10.9.1",
35+
"typescript": "^4.9.5"
3636
}
3737
}

src/enum/guard.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { isEnum } from '../types';
22
import { Optional } from '../global';
33
import PowerGuardError from '../error';
44

5-
function guard<T>(enumObject: T, x: unknown): T[keyof T];
6-
function guard<T>(enumObject: T, x: unknown, optional: true): Optional<T[keyof T]>;
7-
function guard<T>(enumObject: T, x: unknown, optional = false): Optional<T[keyof T]> {
5+
function guard<T extends Record<string, unknown>>(enumObject: T, x: unknown): T[keyof T];
6+
function guard<T extends Record<string, unknown>>(enumObject: T, x: unknown, optional: true): Optional<T[keyof T]>;
7+
function guard<T extends Record<string, unknown>>(enumObject: T, x: unknown, optional = false): Optional<T[keyof T]> {
88
if (isEnum(enumObject)(x)) {
99
return x;
1010
}

src/enum/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { GuardClass, GuardFunctionWithArray, OptionalGuardFunctionWithArray } fr
44

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

7-
class EnumGuard<T> implements GuardClass<EnumType<T>> {
8-
static create<T>(enumObject: T) {
7+
class EnumGuard<T extends Record<string, unknown>> implements GuardClass<EnumType<T>> {
8+
static create<T extends Record<string, unknown>>(enumObject: T) {
99
return new EnumGuard(enumObject);
1010
}
1111

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const isNull = (x: unknown): x is null => x === null;
1313

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

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

1919
export const isArray = <T>(elemGuard: Guard<T>) => (x: unknown): x is Array<T> =>

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"allowSyntheticDefaultImports": true,
99
"strict": true,
1010
"forceConsistentCasingInFileNames": true,
11-
"module": "commonjs",
1211
"moduleResolution": "node",
1312
"resolveJsonModule": true,
1413
"isolatedModules": true,

0 commit comments

Comments
 (0)