From 7403bafd250c14f4c675da86e0dd0c92062a984c Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 8 May 2023 03:03:13 +0800 Subject: [PATCH] fix: standard in typescript --- package.json | 4 ++-- tsconfig.eslint.json | 6 ++++++ types/index.d.ts | 20 ++++++++++---------- types/index.test-d.ts | 6 +++--- 4 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 tsconfig.eslint.json diff --git a/package.json b/package.json index b9483ad..6c94de7 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "types": "types/index.d.ts", "scripts": { - "lint": "standard", + "lint": "ts-standard", "test": "npm run test:unit && npm run test:typescript", "test:unit": "tap", "test:typescript": "tsd" @@ -28,8 +28,8 @@ "homepage": "https://github.com/fastify/fastify-error#readme", "devDependencies": { "benchmark": "^2.1.4", - "standard": "^17.0.0", "tap": "^16.0.0", + "ts-standard": "^12.0.2", "tsd": "^0.28.0" }, "tsd": { diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000..1c10b8a --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "strict": true, + "noImplicitAny": true + } +} diff --git a/types/index.d.ts b/types/index.d.ts index 9591a93..2783e7d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,19 +1,19 @@ -declare function createError(code: C, message: string, statusCode: SC, Base?: Error): createError.FastifyErrorConstructor<{ code: C; statusCode: SC }>; -declare function createError(code: C, message: string, statusCode?: number, Base?: Error): createError.FastifyErrorConstructor<{ code: C; }>; +declare function createError (code: C, message: string, statusCode: SC, Base?: Error): createError.FastifyErrorConstructor<{ code: C, statusCode: SC }> +declare function createError (code: C, message: string, statusCode?: number, Base?: Error): createError.FastifyErrorConstructor<{ code: C }> -type CreateError = typeof createError; +type CreateError = typeof createError declare namespace createError { export interface FastifyError extends Error { - code: string; - name: string; - statusCode?: number; + code: string + name: string + statusCode?: number } - export interface FastifyErrorConstructor { - new (a?: any, b?: any, c?: any): FastifyError & E; - (a?: any, b?: any, c?: any): FastifyError & E; - readonly prototype: FastifyError & E; + export interface FastifyErrorConstructor { + new (a?: any, b?: any, c?: any): FastifyError & E + (a?: any, b?: any, c?: any): FastifyError & E + readonly prototype: FastifyError & E } export const createError: CreateError diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 37d7fc3..f31aa35 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -7,12 +7,12 @@ const err = new CustomError() expectType(err) expectType<'ERROR_CODE'>(err.code) expectType(err.message) -expectType(err.statusCode!) +expectType(err.statusCode) const CustomTypedError = createError('OTHER_CODE', 'message', 400) -expectType>(CustomTypedError) +expectType>(CustomTypedError) const typed = new CustomTypedError() -expectType(typed) +expectType(typed) expectType<'OTHER_CODE'>(typed.code) expectType(typed.message) expectType<400>(typed.statusCode)