# CollapseRestElement

`type` in `services` · v0.7.1

<https://docs.seedcord.org/packages/services/0.7.1/types/collapse-rest-element-2>

Transforms a tuple type by replacing it's rest element with a single element that has the same type as the rest element, while keeping all the non-rest elements intact.

## Examples

```ts
type A = CollapseRestElement<[string, string, ...number[]]>;
//=> [string, string, number]

type B = CollapseRestElement<[...string[], number, number]>;
//=> [string, number, number]

type C = CollapseRestElement<[string, string, ...Array<number | bigint>]>;
//=> [string, string, number | bigint]

type D = CollapseRestElement<[string, number]>;
//=> [string, number]

Note: Optional modifiers (?) are removed from elements unless the exactOptionalPropertyTypes compiler option is disabled. When disabled, there's an additional | undefined for optional elements.
```

```ts
// `exactOptionalPropertyTypes` enabled
type A = CollapseRestElement<[string?, string?, ...number[]]>;
//=> [string, string, number]

// `exactOptionalPropertyTypes` disabled
type B = CollapseRestElement<[string?, string?, ...number[]]>;
//=> [string | undefined, string | undefined, number]
```

## Declaration

```ts
type CollapseRestElement<TArray extends UnknownArray> = IfNotAnyOrNever<
    TArray,
    _CollapseRestElement<TArray>
>;
```
