Merge pull request #31283 from BendingBender/file-type

Enable strictNullChecks for file-type
This commit is contained in:
Jesse Trinity
2018-12-13 16:12:49 -08:00
committed by GitHub
3 changed files with 21 additions and 5 deletions
+3 -1
View File
@@ -1,6 +1,8 @@
import fileType = require("file-type");
// $ExpectType FileTypeResult | null
fileType(new Buffer([0xFF, 0xD8, 0xFF]));
fileType(new Uint8Array([0xFF, 0xD8, 0xFF]));
const minimumBytes: number = fileType.minimumBytes;
// $ExpectType number
fileType.minimumBytes;
+16 -2
View File
@@ -1,4 +1,4 @@
// Type definitions for file-type 5.2
// Type definitions for file-type 10.6
// Project: https://github.com/sindresorhus/file-type
// Definitions by: KIM Jaesuck a.k.a. gim tcaesvk <https://github.com/tcaesvk>
// BendingBender <https://github.com/BendingBender>
@@ -8,7 +8,17 @@
export = FileType;
declare function FileType(buf: Buffer | Uint8Array): FileType.FileTypeResult;
/**
* The file type is detected by checking the
* [magic number](http://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
*
* @param buf It only needs the first `.minimumBytes` bytes. The exception is detection of
* `docx`, `pptx`, and `xlsx` which potentially requires reading the whole file.
* @returns an Object with:
* - ext - One of the [supported file types](https://github.com/sindresorhus/file-type/blob/master/readme.md#supported-file-types)
* - mime - The [MIME type](http://en.wikipedia.org/wiki/Internet_media_type)
*/
declare function FileType(buf: Buffer | Uint8Array): FileType.FileTypeResult | null;
declare namespace FileType {
interface FileTypeResult {
@@ -16,5 +26,9 @@ declare namespace FileType {
mime: string;
}
/**
* The minimum amount of bytes needed to detect a file type. Currently,
* it's 4100 bytes, but it can change, so don't hard-code it.
*/
const minimumBytes: number;
}
+2 -2
View File
@@ -6,7 +6,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
@@ -20,4 +20,4 @@
"index.d.ts",
"file-type-tests.ts"
]
}
}