diff --git a/types/content-type/content-type-tests.ts b/types/content-type/content-type-tests.ts index 0705d440c1..4be9519a94 100644 --- a/types/content-type/content-type-tests.ts +++ b/types/content-type/content-type-tests.ts @@ -1,18 +1,19 @@ -import contentType = require('content-type'); -import express = require('express'); +/// -let obj = contentType.parse('image/svg+xml; charset=utf-8'); +import * as contentType from 'content-type'; +import * as http from 'http'; -console.log(obj.type); // => 'image/svg+xml' -console.log(obj.parameters.charset); // => 'utf-8' +const mediaType = contentType.parse('image/svg+xml; charset=utf-8'); +mediaType; // $ExpectType ParsedMediaType +mediaType.type; // $ExpectType string +mediaType.parameters; // $ExpectType { [key: string]: string; } -let req: express.Request; -obj = contentType.parse(req); +http.createServer((req, res) => { + contentType.parse(req); + contentType.parse(res); +}); -let res: express.Response; -obj = contentType.parse(res); - -let str: string = contentType.format({type: 'image/svg+xml'}); - -let media: contentType.MediaType; -contentType.format(media); +// $ExpectType string +contentType.format({type: 'image/svg+xml'}); +contentType.format({type: 'image/svg+xml', parameters: {charset: 'utf-8'}}); +contentType.format(mediaType); diff --git a/types/content-type/index.d.ts b/types/content-type/index.d.ts index ec60de446f..5ff4ae7ff1 100644 --- a/types/content-type/index.d.ts +++ b/types/content-type/index.d.ts @@ -1,21 +1,26 @@ // Type definitions for content-type 1.1 // Project: https://www.npmjs.com/package/content-type // Definitions by: Hiroki Horiuchi +// BendingBender // Definitions: https://github.com/borisyankov/DefinitelyTyped -import * as express from 'express'; +export function parse(input: RequestLike | ResponseLike | string): ParsedMediaType; +export function format(obj: MediaType): string; -declare var ct: ct.StaticFunctions; -export = ct; - -declare namespace ct { - interface StaticFunctions { - parse(input: express.Request | express.Response | string): MediaType; - format(obj: MediaType): string; - } - - interface MediaType { - type: string; - parameters?: any; - } +export interface ParsedMediaType { + type: string; + parameters: {[key: string]: string}; +} + +export interface MediaType { + type: string; + parameters?: {[key: string]: string}; +} + +export interface RequestLike { + headers: {[header: string]: string | string[]}; +} + +export interface ResponseLike { + getHeader(name: string): number | string | string[] | undefined; } diff --git a/types/content-type/tsconfig.json b/types/content-type/tsconfig.json index 4eaa2f42f4..3361989225 100644 --- a/types/content-type/tsconfig.json +++ b/types/content-type/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -19,4 +19,4 @@ "index.d.ts", "content-type-tests.ts" ] -} \ No newline at end of file +}