Add type definitions for fs-readfile-promise.

This commit is contained in:
mtsg 2017-12-24 16:15:17 +09:00
parent dc0c4811d4
commit 922ea86c89
4 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,32 @@
import * as readFile from "fs-readfile-promise";
declare const path: string;
declare const encoding: string;
declare const nullable: null;
declare const options: { encoding: string, flag: string };
async function testPathOnly() {
return readFile(path);
}
async function testPathEncoding() {
return readFile(path, encoding);
}
async function testPathNull() {
return readFile(path, nullable);
}
async function testPathOption() {
return readFile(path, options);
}
testPathOnly()
.then(console.log)
.catch(console.log);
testPathEncoding()
.then(console.log)
.catch(console.log);
testPathNull()
.then(console.log)
.catch(console.log);
testPathOption()
.then(console.log)
.catch(console.log);

29
types/fs-readfile-promise/index.d.ts vendored Normal file
View File

@ -0,0 +1,29 @@
// Type definitions for fs-readfile-promise 3.0
// Project: https://github.com/shinnn/fs-readfile-promise
// Definitions by: Motosugi Murata <https://github.com/mtsg>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { PathLike } from "fs";
type PathType = PathLike | number;
type OptionsType = { encoding: string; flag?: string; } | string;
export = fsReadFilePromise;
/**
* Asynchronously reads the entire contents of a file.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*/
declare function fsReadFilePromise(path: PathType, options: OptionsType): Promise<string>;
/**
* Asynchronously reads the entire contents of a file.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
*/
declare function fsReadFilePromise(path: PathType, options?: null): Promise<Buffer>;
declare namespace fsReadFilePromise { }

View File

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

View File

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