From 413069ccfa0f525b9cf872be9349c424fad1b322 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Tue, 7 May 2019 15:54:23 -0400 Subject: [PATCH] Update types to handle tmp upgrade, with a test --- index.d.ts | 28 +++++++++++++++++----------- index.test-d.ts | 27 +++++++++++++++++++++++++++ package.json | 9 ++++++--- 3 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 index.test-d.ts diff --git a/index.d.ts b/index.d.ts index bfefd3f..fd21f1e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,21 +1,27 @@ -import { fileSync, dirSync, tmpNameSync, setGracefulCleanup } from 'tmp'; -import { Options, SimpleOptions } from 'tmp'; +import { fileSync, dirSync, tmpNameSync, setGracefulCleanup } from "tmp"; +import { FileOptions, DirOptions, TmpNameOptions } from "tmp"; export interface DirectoryResult { - path: string; - cleanup(): void; + path: string; + cleanup(): void; } export interface FileResult extends DirectoryResult { - fd: number; + fd: number; } -export function file(options?: Options): Promise; -export function withFile(fn: (result: FileResult) => Promise, options?: Options): Promise; +export function file(options?: FileOptions): Promise; +export function withFile( + fn: (result: FileResult) => Promise, + options?: FileOptions +): Promise; -export function dir(options?: Options): Promise; -export function withDir(fn: (results: DirectoryResult) => Promise, options?: Options): Promise; +export function dir(options?: DirOptions): Promise; +export function withDir( + fn: (results: DirectoryResult) => Promise, + options?: DirOptions +): Promise; -export function tmpName(options?: SimpleOptions): Promise; +export function tmpName(options?: TmpNameOptions): Promise; -export { fileSync, dirSync, tmpNameSync, setGracefulCleanup } \ No newline at end of file +export { fileSync, dirSync, tmpNameSync, setGracefulCleanup }; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..4ab5965 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,27 @@ +import { file, withFile, dir, withDir, tmpName } from "."; + +async function fileExample() { + const { path, fd, cleanup } = await file({ discardDescriptor: true }); + + await withFile( + async ({ path, fd, cleanup }) => { + console.log(fd); + }, + { discardDescriptor: true } + ); +} + +async function dirExample() { + const { path, cleanup } = await dir({ unsafeCleanup: true }); + + await withDir( + async ({ path, cleanup }) => { + console.log(path); + }, + { unsafeCleanup: true } + ); +} + +async function tmpNameExample() { + const name = await tmpName({ tries: 3 }); +} diff --git a/package.json b/package.json index d2a7a99..22b4d2d 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "main": "index.js", "types": "index.d.ts", "scripts": { - "test": "mocha" + "mocha": "mocha", + "check-types": "tsd", + "test": "npm run mocha && npm run check-types" }, "keywords": [ "tmp", @@ -25,7 +27,8 @@ "tmp": "0.1.0" }, "devDependencies": { - "@types/tmp": "0.0.33", - "mocha": "^3.1.2" + "@types/tmp": "0.1.0", + "mocha": "^3.1.2", + "tsd": "^0.7.2" } }