@zanganken/ts-join
v0.1.0
Published
Global typing utility for ReadonlyArray.join to return the value of it as a type
Maintainers
Readme
ts-join
Global typing utility for ReadonlyArray.join to return the value of it as a type
Without ts-join:
join(inArrayandReadonlyArray) returnsstringjoin(inArrayandReadonlyArray) doesn't react if asymbolis contained inside the array the method is being applied to
With ts-join:
arr.join(s)returns the expected result of thejoinoperation whenarris of typereadonly any[]andsis a constantstringjoin(inArrayandReadonlyArray) returnsneverif asymbolis contained inside the array the method is being applied to
Install
npm install --save-dev @zanganken/ts-joinUsage
As a simple helper
Create a ts-join.d.ts file in your project with these contents:
// Do not add any other lines of code to this file!
import "@zanganken/ts-join";As a dependency in your project
For these imports to work, you'll need to ensure that, in your
tsconfig.json,moduleResolutionis set toNodeNext,Node16orBundler.
Import arrayJoin() in your project and use it like this:
import { arrayJoin } from "@zanganken/ts-join/array-join";
// returns "a/b/c" as a type
const something = arrayJoin(<const>["a", "b", "c"], "/")or
Import ArrayJoin<T, S> to use it as a type in your projects:
import { type ArrayJoin } from "@zanganken/ts-join/array-join";
// returns "a/b/c" as a type
type Something = ArrayJoin<readonly ["a", "b", "c"], "/">