@isbl/ts-utils
v1.0.1
Published
Useful typescript helpers
Downloads
10
Readme
@isbl/ts-utils
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