Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propEq type doesn't account for optional properties #87

Open
jmarks-joshua opened this issue Jan 18, 2024 · 1 comment
Open

propEq type doesn't account for optional properties #87

jmarks-joshua opened this issue Jan 18, 2024 · 1 comment

Comments

@jmarks-joshua
Copy link

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.

@Harris-Miller
Copy link
Collaborator

We actually have an open MR for this, along with some other typing issues for propEq: #74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants