TS2383
TS2383: Overload signatures must all be exported or non-exported.
Broken Code ❌
function isTuple<T>(arr: T[], minLength: 1): arr is [T];
function isTuple<T>(arr: T[], minLength: 2): arr is [T, T];
function isTuple<T>(arr: T[], minLength: 3): arr is [T, T, T];
function isTuple<T>(arr: T[], minLength: 4): arr is [T, T, T, T];
export function isTuple<T>(arr: T[], minLength: number) {
return arr.length >= minLength;
}Solution:
This TypeScript error occurs because the function overloads for isTuple are internally defined (not exported), but the implementation signature is exported. This discrepancy between the visibility of the overload signatures and the implementation signature leads to the error.
To fix this error, you need to ensure consistent export status for all overload signatures and the function implementation. You can either export all the overload signatures or keep them all internal. In most cases, if you intend to use the function outside the module, you should export everything.
Fixed Code ✔️
export function isTuple<T>(arr: T[], minLength: 1): arr is [T];
export function isTuple<T>(arr: T[], minLength: 2): arr is [T, T];
export function isTuple<T>(arr: T[], minLength: 3): arr is [T, T, T];
export function isTuple<T>(arr: T[], minLength: 4): arr is [T, T, T, T];
export function isTuple<T>(arr: T[], minLength: number) {
return arr.length >= minLength;
}