Skip to content

PathLike type

pathlib-ts > PathLike

Union of string-like inputs accepted by path constructors and helpers.

Signature:

export type PathLike = string | PurePath;

References: PurePath

CPython accepts both str and path objects for most APIs. The TypeScript port mirrors this behaviour by accepting plain strings alongside PurePath instances. Concrete Path objects also satisfy the contract because they extend PurePath.

Accepting both strings and paths

import { Path, PathLike } from "pathlib-ts";
function ensurePath(value: PathLike): Path {
return value instanceof Path ? value : new Path(value);
}
const input = ensurePath("./tmp/output");
console.log(input.toString());