ramda/types

Type inference on ifElse

Closed this issue · 5 comments

Hello , just wanted to leave this here, the type inference of the ifElse function seems to not be working in this case:

image

Bests!

Could you provide the given typescript error?

import { always, ifElse, isNotNil } from "ramda";

const processLanguageFromHeader = (value: string ) => value

const parseLanguageHeader = ifElse(isNotNil, processLanguageFromHeader, always('en'))

const test = (value: string | null) => parseLanguageHeader(value);

This is a sample of the code, ifElse seems to not exclude the null part and typescript says:

image

Please submit typing issues over at https://github.com/ramda/types/

isNotNil can remove null | undefined from a type, but it cannot infer that the incoming generic is T | null | undefined
You can set the generic yourself though on the function pointer isNotNil<string | null>

Playground link with full example: https://tsplay.dev/WyzJdw

Did not know I can pass types to Ramda functions great! thanks a lot for it.