prefer-ts-extras-array-join
Prefer arrayJoin from ts-extras over array.join(...).
arrayJoin(...) can preserve stronger tuple-aware typing when joining array values.
Targeted pattern scopeโ
This rule focuses on direct array.join(separator) calls that can be migrated to arrayJoin(array, separator) with deterministic fixes.
array.join(separator)call sites that can usearrayJoin(array, separator).
Alias indirection, wrapper helpers, and non-canonical call shapes are excluded to keep arrayJoin(array, separator) migrations safe.
What this rule reportsโ
This rule reports array.join(separator) call sites when arrayJoin(array, separator) is the intended replacement.
array.join(separator)call sites that can usearrayJoin(array, separator).
Why this rule existsโ
arrayJoin keeps string assembly consistent and can preserve stronger string typing when arrays and separators are literals.
- Join operations use one helper style across modules.
- Literal-based join results are inferred more precisely in typed utilities.
- Join-heavy code paths avoid mixed native/helper patterns.
โ Incorrectโ
const key = segments.join(":");
โ Correctโ
const key = arrayJoin(segments, ":");
Behavior and migration notesโ
- Runtime behavior matches native
Array.prototype.join. - Missing separator still defaults to
",". nullandundefinedentries are converted to empty strings, matching native behavior.
Additional examplesโ
โ Incorrect โ Additional exampleโ
const route = segments.join("/");
โ Correct โ Additional exampleโ
const route = arrayJoin(segments, "/");
โ Correct โ Repository-wide usageโ
const csv = arrayJoin(columns, ",");
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-ts-extras-array-join": "error",
},
},
];
When not to use itโ
Disable this rule if your codebase requires native .join() for API consistency.
Package documentationโ
ts-extras package documentation:
Source file: source/array-join.ts
/**
A strongly-typed version of `Array#join()` that preserves literal string types.
The built-in `Array#join()` always returns `string`, losing type information. This function returns a properly-typed template literal when given a tuple of literals.
@example
```
import {arrayJoin} from 'ts-extras';
// Literal types are preserved automatically
const joined = arrayJoin(['foo', 'bar', 'baz'], '-');
//=> 'foo-bar-baz'
// ^? 'foo-bar-baz'
const dotPath = arrayJoin(['a', 'b', 'c'], '.');
//=> 'a.b.c'
// ^? 'a.b.c'
// Dynamic arrays return string
const dynamic: string[] = ['a', 'b'];
const dynamicJoined = arrayJoin(dynamic, '-');
//=> string
```
@category Improved builtin
*/
Rule catalog ID: R008