Skip to content

propEq type doesn't account for optional properties #87

@jmarks-joshua

Description

@jmarks-joshua
type DemoType = {
	optionalProp?: string
}

const filteredList = propEq('Yes', 'optionalProp')({ optionalProp: 'Yes' } as DemoType)

This produces this error:

Argument of type 'DemoType' is not assignable to parameter of type 'Record<"optionalProp", string>'. Types of property 'optionalProp' are incompatible. Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.

I feel like this should work just fine? The code runs as expected, just produces a the error.

it doesn't error if you pass all parameters at the same time rather than using the curried functions. I'm really not sure why.
propEq('Yes', 'optionalProp', { optionalProp: 'Yes' } as DemoType)

I've forked the project and written a failing test, but sadly I'm not proficient enough at typescript to write something that does any type guarding but allows my use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions