koa-respond
koa-respond copied to clipboard
Publish TypeScript definitions
I'd love to use this in TypeScript, but there are no definitions 😬
I'm happy to contribute them, but I'm pretty busy right now, so I'm making an issue in the meantime incase someone's already made some, or wants to have a whack :)
I'll be publishing them to @types
, unless you'd like them here.
@G-Rath I created a repo that is inspired by koa-respond
, it built with typescript. Typing hint is out of the box, so you enjoy it without installing any @types
dependencies.
import * as Koa from 'koa';
declare module 'koa' {
interface ExtendableContext {
ok: (response?: string|object) => Koa.Context;
created: (response?: string|object) => Koa.Context;
noContent: (response?: string|object) => Koa.Context;
badRequest: (response?: string|object) => Koa.Context;
unauthorized: (response?: string|object) => Koa.Context;
forbidden: (response?: string|object) => Koa.Context;
notFound: (response?: string|object) => Koa.Context;
locked: (response?: string|object) => Koa.Context;
internalServerError: (response?: string|object) => Koa.Context;
notImplemented: (response?: string|object) => Koa.Context;
}
}
Simple declaration that gets you past the compiler (I don't know much about creating types for other repos)
@G-Rath are you still planning to publish the types?
Sorry, I missed this issue.
I didn't originally do this in TS because specifying custom context in Koa is already a mess as you would have to create your own context type that is the union of the contexts of all the libs you use.
Feel free to publish the typings on DT though.
Hey @ignaciojcano where in your project did you put the module declaration?
Hey @ignaciojcano where in your project did you put the module declaration?
@tevonsb created a types/koa-respond/index.d.ts
but the important part is to tell the TS compiler where your types are, so also add "typeRoots": ["./types", "./node_modules/@types"]
to your compilerOptions
in your tsconfig. (notice that i only added ./types
folder
Thanks @ignaciojcano this helped us.