From 3f28071fcbb72a4541d5f0db12ee9c215b5b6fcf Mon Sep 17 00:00:00 2001 From: Yerden Date: Thu, 11 Jul 2019 03:23:07 +0600 Subject: [PATCH] NEW: Type definitions for koa-dec-router (#36696) * NEW: Type definitions for koa-dec-router * FIX: Type definitions for koa-dec-router --- types/koa-dec-router/index.d.ts | 33 ++++++++++++++++ types/koa-dec-router/koa-dec-router-tests.ts | 40 ++++++++++++++++++++ types/koa-dec-router/tsconfig.json | 25 ++++++++++++ types/koa-dec-router/tslint.json | 3 ++ 4 files changed, 101 insertions(+) create mode 100644 types/koa-dec-router/index.d.ts create mode 100644 types/koa-dec-router/koa-dec-router-tests.ts create mode 100644 types/koa-dec-router/tsconfig.json create mode 100644 types/koa-dec-router/tslint.json diff --git a/types/koa-dec-router/index.d.ts b/types/koa-dec-router/index.d.ts new file mode 100644 index 0000000000..a0fa14ea9a --- /dev/null +++ b/types/koa-dec-router/index.d.ts @@ -0,0 +1,33 @@ +// Type definitions for koa-dec-router 0.0 +// Project: https://github.com/zaaack/koa-dec-router +// Definitions by: Yerden Kembayev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.7 + +export const CTRL_PATH: symbol; + +export const MIDDLEWARES: symbol; + +export const OPTIONS: symbol; + +export const ROUTES: symbol; + +export function controller(path: any, opts?: any, ...args: any[]): any; + +export function route(method: string, path: any, opts?: any, ...args: any[]): any; + +export function get(...args: any[]): any; + +export function head(...args: any[]): any; + +export function patch(...args: any[]): any; + +export function post(...args: any[]): any; + +export function put(...args: any[]): any; + +export function del(...args: any[]): any; + +export function all(...args: any[]): any; + +export default function(opts: any): any; diff --git a/types/koa-dec-router/koa-dec-router-tests.ts b/types/koa-dec-router/koa-dec-router-tests.ts new file mode 100644 index 0000000000..9573a1781a --- /dev/null +++ b/types/koa-dec-router/koa-dec-router-tests.ts @@ -0,0 +1,40 @@ +import DecRouter, { controller, get, post } from 'koa-dec-router'; + +class Ctx { + body: any; + params: any; +} + +const bazHandler = (ctx: Ctx, next: () => void) => { + next(); +}; + +@controller('/foo') +export class FooController { + @get('/baz') + async fooBaz(ctx: Ctx) { + ctx.body = '/foo/baz'; + } + + @get() + async foo(ctx: Ctx) { + ctx.body = '/foo'; + } + + @get('/:code', { priority: -1 }) + async fooCode(ctx: Ctx) { + ctx.body = '/foo/' + ctx.params.code; + } +} + +@controller('/baz', bazHandler) +export class BazController { + @get('/foo') + async fooBaz(ctx: Ctx) { + ctx.body = '/foo/baz'; + } +} + +const decRouter = DecRouter({ + controllersDir: './' +}); diff --git a/types/koa-dec-router/tsconfig.json b/types/koa-dec-router/tsconfig.json new file mode 100644 index 0000000000..9c5b385e0e --- /dev/null +++ b/types/koa-dec-router/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "experimentalDecorators": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "koa-dec-router-tests.ts" + ] +} diff --git a/types/koa-dec-router/tslint.json b/types/koa-dec-router/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/koa-dec-router/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}