mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-29 00:18:20 +08:00
Improve temp function signatures (#11774)
This commit is contained in:
committed by
Mohamed Hegazy
parent
9d5fc54dd5
commit
428195bee2
45
temp/index.d.ts
vendored
45
temp/index.d.ts
vendored
@@ -8,34 +8,45 @@
|
||||
import * as temp from "temp";
|
||||
import * as fs from "fs";
|
||||
|
||||
export interface OpenFile {
|
||||
path: string;
|
||||
fd: number;
|
||||
}
|
||||
|
||||
export interface Stats {
|
||||
files: number;
|
||||
dirs: number;
|
||||
}
|
||||
|
||||
export interface AffixOptions {
|
||||
prefix?: string;
|
||||
suffix?: string;
|
||||
dir?: string;
|
||||
prefix?: string;
|
||||
suffix?: string;
|
||||
dir?: string;
|
||||
}
|
||||
|
||||
export declare var dir: string;
|
||||
|
||||
export declare function track(value?: boolean): typeof temp;
|
||||
|
||||
export declare function mkdir(affixes: string, callback?: (err: any, dirPath: string) => void): void;
|
||||
export declare function mkdir(affixes: AffixOptions, callback?: (err: any, dirPath: string) => void): void;
|
||||
export declare function mkdir(affixes?: string, callback?: (err: any, dirPath: string) => void): void;
|
||||
export declare function mkdir(affixes?: AffixOptions, callback?: (err: any, dirPath: string) => void): void;
|
||||
|
||||
export declare function mkdirSync(affixes: string): string;
|
||||
export declare function mkdirSync(affixes: AffixOptions): string;
|
||||
export declare function mkdirSync(affixes?: string): string;
|
||||
export declare function mkdirSync(affixes?: AffixOptions): string;
|
||||
|
||||
export declare function open(affixes: string, callback?: (err: any, result: { path: string, fd: number }) => void): void;
|
||||
export declare function open(affixes: AffixOptions, callback?: (err: any, result: { path: string, fd: number }) => void): void;
|
||||
export declare function open(affixes?: string, callback?: (err: any, result: OpenFile) => void): void;
|
||||
export declare function open(affixes?: AffixOptions, callback?: (err: any, result: OpenFile) => void): void;
|
||||
|
||||
export declare function openSync(affixes: string): { path: string, fd: number };
|
||||
export declare function openSync(affixes: AffixOptions): { path: string, fd: number };
|
||||
export declare function openSync(affixes?: string): OpenFile;
|
||||
export declare function openSync(affixes?: AffixOptions): OpenFile;
|
||||
|
||||
export declare function path(affixes: string, defaultPrefix?: string): string;
|
||||
export declare function path(affixes: AffixOptions, defaultPrefix?: string): string;
|
||||
export declare function path(affixes?: string, defaultPrefix?: string): string;
|
||||
export declare function path(affixes?: AffixOptions, defaultPrefix?: string): string;
|
||||
|
||||
export declare function cleanup(callback?: (result: boolean | { files: number, dirs?: number }) => void): void;
|
||||
export declare function cleanup(callback?: (result: boolean | Stats) => void): void;
|
||||
|
||||
export declare function cleanupSync(): boolean | { files: number, dirs: number };
|
||||
export declare function cleanupSync(): boolean | Stats;
|
||||
|
||||
export declare function createWriteStream(affixes?: string): fs.WriteStream;
|
||||
export declare function createWriteStream(affixes?: AffixOptions): fs.WriteStream;
|
||||
|
||||
export declare function createWriteStream(affixes: string): fs.WriteStream;
|
||||
export declare function createWriteStream(affixes: AffixOptions): fs.WriteStream;
|
||||
|
||||
@@ -16,7 +16,7 @@ function testCleanup() {
|
||||
}
|
||||
|
||||
function testCleanupSync() {
|
||||
const cleanupResult = temp.cleanupSync()
|
||||
const cleanupResult: boolean | temp.Stats = temp.cleanupSync()
|
||||
if (typeof cleanupResult === "boolean") {
|
||||
const x = cleanupResult === true;
|
||||
}
|
||||
@@ -42,13 +42,14 @@ function testOpen() {
|
||||
}
|
||||
|
||||
function testOpenSync() {
|
||||
const { fd: openFd1, path: openPath1 } = temp.openSync({ dir: "tempDir", prefix: "pref", suffix: "suff" });
|
||||
const { fd: openFd2, path: openPath2 } = temp.openSync("str");
|
||||
const f1: temp.OpenFile = temp.openSync({ dir: "tempDir", prefix: "pref", suffix: "suff" });
|
||||
const f2: temp.OpenFile = temp.openSync("str");
|
||||
}
|
||||
|
||||
function testCreateWriteStream() {
|
||||
const stream = temp.createWriteStream("HelloStreamAffix");
|
||||
stream.write("data");
|
||||
const stream2 = temp.createWriteStream();
|
||||
}
|
||||
|
||||
function testMkdir() {
|
||||
@@ -73,4 +74,4 @@ function testTrack() {
|
||||
const tempChained = temp.track().track(true).track(false);
|
||||
tempChained.dir;
|
||||
tempChained.cleanupSync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user