[fresh] add typings (#18990)

This commit is contained in:
Dimitri Benin 2017-08-15 21:23:20 +02:00 committed by Mohamed Hegazy
parent 62cadd0386
commit 8db0c98591
4 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,28 @@
/// <reference types="node" />
import fresh = require('fresh');
import * as http from 'http';
let reqHeaders = { 'if-none-match': '"foo"' };
let resHeaders = { etag: '"bar"' };
// $ExpectType boolean
fresh(reqHeaders, resHeaders);
const server = http.createServer((req, res) => {
if (isFresh(req, res)) {
res.statusCode = 304;
res.end();
return;
}
res.statusCode = 200;
res.end('hello, world!');
});
function isFresh(req: http.IncomingMessage, res: http.ServerResponse) {
return fresh(req.headers, {
etag: res.getHeader('ETag'),
'last-modified': res.getHeader('Last-Modified')
});
}
server.listen(3000);

14
types/fresh/index.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
// Type definitions for fresh 0.5
// Project: https://github.com/jshttp/fresh#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = fresh;
declare function fresh(reqHeaders: fresh.Headers, resHeaders: fresh.Headers): boolean;
declare namespace fresh {
interface Headers {
[header: string]: string | string[] | number | undefined;
}
}

22
types/fresh/tsconfig.json Normal file
View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"fresh-tests.ts"
]
}

1
types/fresh/tslint.json Normal file
View File

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