denoland / denoland/std

General-purpose utility types/type guards (maybe in a new `types` package scope)

Open
#6,735 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

There are various common utility types that aren't available in TypeScript's built-in libraries. For example:

```ts
export type NonEmptyArray = [T, ...T[]]
export function isNonEmptyArray(arr: T[]): arr is NonEmptyArray {
return arr.length > 0
}
```

In some cases, these can be somewhat complex, in others (like `NonEmptyArray`) implementation is somewhat trivial, but also involves design decisions where the tradeoffs may not be initially obvious — for example, what if anything is the practical difference between `[T, ...T[]]` vs `T[] & { 0: T }`?

**Describe the solution you'd like**

Maybe a new `@std/types` package scope? That would be the first place I'd look for this kind of thing.

The only existing examples I know of in std are `ExpandRecursively` under `collections/deep-merge`, but there may be a few more.

**Describe alternatives you've considered**

Include type utils distributed in various other packages, but that's likely to be less discoverable — I only stumbled upon `ExpandRecursively` by accident after re-implementing similar logic multiple times.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.