mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Merge pull request #22471 from darkwebdev/kraken-js
@types/kraken-js - Fix callback arguments type, add tests
This commit is contained in:
Vendored
+6
-4
@@ -5,22 +5,24 @@
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
import { Express } from 'express';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
declare function k(options?: k.Options | string): Express;
|
||||
|
||||
declare namespace k {
|
||||
interface Kraken extends Express {
|
||||
once(name: string, cb: (err: Error | null, result?: any) => any): void;
|
||||
interface Kraken extends Express, EventEmitter {
|
||||
kraken: Kraken;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
protocols?: object;
|
||||
basedir?: string;
|
||||
configdir?: string;
|
||||
mountpath?: string;
|
||||
inheritViews?: boolean;
|
||||
startupHeaders?: Map<string, string>;
|
||||
onconfig?(config: object, next: (err: Error | null, config?: object) => any): any;
|
||||
startupHeaders?: { [key: string]: string; };
|
||||
onconfig?(config: Map<string, any>, next: (err: Error | null, config?: object) => any): any;
|
||||
uncaughtException?(err: Error): any;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import express = require('express');
|
||||
import kraken = require('kraken-js');
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
import { readFile } from 'fs';
|
||||
|
||||
const app = express() as kraken.Kraken;
|
||||
|
||||
@@ -13,16 +14,55 @@ kraken('path/to/options');
|
||||
|
||||
// $ExpectType Express
|
||||
kraken({
|
||||
onconfig: (config, next) => {
|
||||
basedir: __dirname,
|
||||
onconfig(config, next) {
|
||||
config.get('view engines:js:renderer:arguments').push(app);
|
||||
config.set('some:string', '/foo');
|
||||
config.set('some:complex:type', [{
|
||||
uncaughtException(error: Error) {
|
||||
next(error);
|
||||
}
|
||||
}]);
|
||||
next(null, config);
|
||||
},
|
||||
protocols: {
|
||||
file(value: string, callback: any) {
|
||||
readFile(value, 'utf8', callback);
|
||||
}
|
||||
},
|
||||
startupHeaders: {
|
||||
'Custom-Header1': 'Header1',
|
||||
'Custom-Header2': 'Header2'
|
||||
},
|
||||
uncaughtException(err) {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
// $ExpectType Kraken
|
||||
app.use(kraken());
|
||||
|
||||
// $ExpectType void
|
||||
app.once('event', (err, result) => {});
|
||||
// $ExpectType Kraken
|
||||
app.use(kraken(__dirname));
|
||||
|
||||
// $ExpectType Kraken
|
||||
app.use(kraken({
|
||||
configdir: 'config',
|
||||
protocols: {
|
||||
custom(value: any) {
|
||||
return `Hello, ${ value }!`;
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
app.listen(8080, (err?: Error) => {
|
||||
console.log('[%s] Listening on http://localhost:%d', app.settings.env, 8080);
|
||||
});
|
||||
|
||||
new Promise(resolve => {
|
||||
// $ExpectType Kraken
|
||||
app.once('event', resolve);
|
||||
});
|
||||
|
||||
// $ExpectType any
|
||||
app.kraken.get('configProp');
|
||||
|
||||
Reference in New Issue
Block a user