What is @types/which?
The @types/which package provides TypeScript type definitions for the 'which' npm package. 'which' is a utility that locates and returns the path to an executable in the system path, similar to the Unix 'which' command. The @types/which package does not contain functionality itself but provides type definitions to help TypeScript developers use the 'which' package with type safety.
What are @types/which's main functionalities?
Type definitions for finding an executable in the path
This code sample demonstrates how to use the 'which' package with TypeScript type definitions provided by @types/which. It attempts to locate the 'node' executable in the system path and prints its location or an error if not found.
import which from 'which';
which('node', (err, resolvedPath) => {
if (err) {
console.error('Node executable not found');
return;
}
console.log('Node executable located at:', resolvedPath);
});
Other packages similar to @types/which
find-exec
find-exec is a package that provides similar functionality to 'which', allowing users to find the path of executables in the system path. Unlike @types/which, find-exec does not require separate type definitions as it may already include TypeScript support or be used in a JavaScript context.
locate-path
locate-path is another package that helps in finding paths of files or directories based on given criteria. While it serves a broader purpose compared to 'which', it can be used to achieve similar results. It differs from @types/which in that it is not specifically focused on executables and does not provide TypeScript types out of the box.
Installation
npm install --save @types/which
Summary
This package contains type definitions for which (https://github.com/isaacs/node-which).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/which.
type AppendNullIfNothrow<TOptions, TRet> = TOptions extends { nothrow: infer TVal }
? TVal extends false
? TRet
: TRet | null
: TRet;
type TransformToArrayIfAll<TOptions, TRet> = TOptions extends { all: infer TVal }
? TVal extends true
? readonly TRet[]
: TVal extends false
? TRet
: readonly TRet[] | TRet
: TRet;
type ReturnType<TOptions> = AppendNullIfNothrow<TOptions, TransformToArrayIfAll<TOptions, string>>;
type Exact<T, U extends T> = {
[Key in keyof U]: Key extends keyof T ? U[Key]
: never;
};
declare function which<TOptions extends which.Options>(
cmd: string,
options?: Exact<which.Options, TOptions>,
): Promise<ReturnType<Exact<which.Options, TOptions>>>;
declare namespace which {
function sync<TOptions extends Options>(
cmd: string,
options?: Exact<Options, TOptions>,
): ReturnType<Exact<Options, TOptions>>;
interface Options {
all?: boolean | undefined;
path?: string | undefined;
pathExt?: string | undefined;
delimiter?: string | undefined;
nothrow?: boolean | undefined;
}
}
export = which;
Additional Details
- Last updated: Thu, 30 May 2024 17:35:42 GMT
- Dependencies: none
Credits
These definitions were written by vvakame, cspotcode, and Piotr Błażejewicz.