@isbl/ts-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@isbl/ts-utils

MIT License npm dependencies Releases

Few utils for working in typescript which I found myself writing over and over again.

notNull

Equivalent to a => a !== null, but also works as type assertion. Usage example:

function removeTwos(input: number[]) {
  return input.map(item => item === 2 ? null : item).filter(notNull)
}

Return type of this function is number[], not (number | null)[] as it would be otherwise.

ArrayElement

Generic type which given array type returns its element. More readable alternative to ArrayType[0], except that it also checks if incoming type is an array. Works for readonly arrays.

type Thing = ArrayElement<string[]> // thing is string

Readme

Keywords

none

Package Sidebar

Install

npm i @isbl/ts-utils

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

3.81 kB

Total Files

8

Last publish

Collaborators

  • bellathewitch