Skip to main content

hasPropertiesDefined

Callable


  • Creates a function that acts as a typeguard that makes all given properties required, by checking if all values on the given property are not equal to undefined.

    Example

    const original = [{ foo: 'bar' }, { foo: undefined }]
    original.filter(hasPropertiesDefined('foo'))
    // => [{ foo: 'bar' }]: { foo: string }[]

    const multiple = [{ foo: 'bar', bar: 'fooz' }, { foo: undefined }]
    original.filter(hasPropertiesDefined('foo'))
    // => [{ foo: 'bar', bar: 'fooz' }]: { foo: string, bar: string }[]
    @deprecated

    will be mostly unneeded in typescript 5.5 https://github.com/microsoft/TypeScript/pull/57465


    Type parameters

    • T

      The filter value input type.

    • K: string | number | symbol

      The keys on T to make required.

    Parameters

    • keys: K | K[]

      The keys to make required in this filter.

    Returns (obj: T | RequireKeys<T, K>) => obj is RequireKeys<T, K>

    The typeguard function.