From b4c23f0e86f8b9efdec48a899fbde5ab2ee6e6c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Mon, 30 Mar 2020 23:40:00 +0100 Subject: [PATCH] [mime-db] Add exported object (#43066) * [mime-db] Add exported object * Use module import style --- types/hapi__mimos/index.d.ts | 5 ++- types/mime-db/index.d.ts | 40 +++++++++++------ types/mime-db/mime-db-tests.ts | 13 ++++++ types/mime-db/tsconfig.json | 5 ++- types/mime-db/tslint.json | 79 +--------------------------------- types/mimos/index.d.ts | 5 ++- 6 files changed, 49 insertions(+), 98 deletions(-) create mode 100644 types/mime-db/mime-db-tests.ts diff --git a/types/hapi__mimos/index.d.ts b/types/hapi__mimos/index.d.ts index 7139e25cc0..6e911b424f 100644 --- a/types/hapi__mimos/index.d.ts +++ b/types/hapi__mimos/index.d.ts @@ -2,10 +2,11 @@ // Project: https://github.com/hapijs/mimos // Definitions by: AJP // Silas Rech +// Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 -import { DataStructure as MimeDbDataStructure } from 'mime-db'; +import { MimeEntry } from 'mime-db'; /** * @@ -20,7 +21,7 @@ export interface MimosOptions { override: {[index: string]: MimosOptionsValue}; } -export interface MimosOptionsValue extends MimeDbDataStructure { +export interface MimosOptionsValue extends MimeEntry { /** specify the type value of result objects, defaults to key. See the example below for more clarification. */ type?: string; /** method with signature function(mime) when this mime type is found in the database, this function will run. This allows you make customizations to mime based on developer criteria. */ diff --git a/types/mime-db/index.d.ts b/types/mime-db/index.d.ts index cf46a0c593..8872920de4 100644 --- a/types/mime-db/index.d.ts +++ b/types/mime-db/index.d.ts @@ -1,21 +1,33 @@ // Type definitions for mime-db 1.27 // Project: https://github.com/jshttp/mime-db // Definitions by: AJP +// Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 -/** - * Data Structure - * If unknown, every property could be undefined. - * @see {@link https://github.com/jshttp/mime-db#data-structure} - */ -export interface DataStructure { - /** where the mime type is defined. If not set, it's probably a custom media type. */ - source?: string; - /** known extensions associated with this mime type. */ - extensions?: string[]; - /** whether a file of this type can be gzipped. */ - compressible?: boolean; - /** the default charset associated with this type, if any. */ - charset?: string; +declare namespace database { + /** + * @see {@link https://github.com/jshttp/mime-db#data-structure} + */ + interface MimeEntry { + /** Where the mime type is defined. If not set, it's probably a custom media type. */ + readonly source?: string; + /** Known extensions associated with this mime type. */ + readonly extensions?: ReadonlyArray; + /** Whether a file of this type can be gzipped. */ + readonly compressible?: boolean; + /** The default charset associated with this type, if any. */ + readonly charset?: string; + } + + /** + * @see {@link https://github.com/jshttp/mime-db#data-structure} + */ + interface MimeDatabase { + readonly [type: string]: MimeEntry; + } } + +declare const database: database.MimeDatabase; + +export = database; diff --git a/types/mime-db/mime-db-tests.ts b/types/mime-db/mime-db-tests.ts new file mode 100644 index 0000000000..213f3371d6 --- /dev/null +++ b/types/mime-db/mime-db-tests.ts @@ -0,0 +1,13 @@ +import database = require('mime-db'); + +// $ExpectType MimeDatabase +database; + +// $ExpectType MimeEntry +database['text/markdown']; + +// $ExpectType ReadonlyArray | undefined +database['text/markdown'].extensions; + +// $ExpectType string +database['text/markdown'].extensions![0]; diff --git a/types/mime-db/tsconfig.json b/types/mime-db/tsconfig.json index abf333c6bf..c74bf359f4 100644 --- a/types/mime-db/tsconfig.json +++ b/types/mime-db/tsconfig.json @@ -17,6 +17,7 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts" + "index.d.ts", + "mime-db-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/mime-db/tslint.json b/types/mime-db/tslint.json index 3d59f55fda..f93cf8562a 100644 --- a/types/mime-db/tslint.json +++ b/types/mime-db/tslint.json @@ -1,80 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "npm-naming": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } diff --git a/types/mimos/index.d.ts b/types/mimos/index.d.ts index 06587e42db..5fc3ea6162 100644 --- a/types/mimos/index.d.ts +++ b/types/mimos/index.d.ts @@ -1,10 +1,11 @@ // Type definitions for mimos 3.0 // Project: https://github.com/hapijs/mimos // Definitions by: AJP +// Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 -import { DataStructure as MimeDbDataStructure } from 'mime-db'; +import { MimeEntry } from 'mime-db'; /** * @@ -19,7 +20,7 @@ export interface MimosOptions { override: {[index: string]: MimosOptionsValue}; } -export interface MimosOptionsValue extends MimeDbDataStructure { +export interface MimosOptionsValue extends MimeEntry { /** specify the type value of result objects, defaults to key. See the example below for more clarification. */ type?: string; /** method with signature function(mime) when this mime type is found in the database, this function will run. This allows you make customizations to mime based on developer criteria. */