NEW: Type definitions for koa-dec-router (#36696)

* NEW: Type definitions for koa-dec-router

* FIX: Type definitions for koa-dec-router
This commit is contained in:
Yerden 2019-07-11 03:23:07 +06:00 committed by Armando Aguirre
parent 74a49e887e
commit 3f28071fcb
4 changed files with 101 additions and 0 deletions

33
types/koa-dec-router/index.d.ts vendored Normal file
View File

@ -0,0 +1,33 @@
// Type definitions for koa-dec-router 0.0
// Project: https://github.com/zaaack/koa-dec-router
// Definitions by: Yerden Kembayev <https://github.com/aarystan>
// 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;

View File

@ -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: './'
});

View File

@ -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"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}