@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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    0
  • 1.0.0
    0
  • 0.2.0
    0

Package Sidebar

Install

npm i @isbl/ts-utils

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

3.81 kB

Total Files

8

Last publish

Collaborators

  • bellathewitch