Type inference on ifElse
Closed this issue · 5 comments
capArturo507 commented
jlissner commented
Could you provide the given typescript error?
capArturo507 commented
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:
Harris-Miller commented
Please submit typing issues over at https://github.com/ramda/types/
Harris-Miller commented
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
capArturo507 commented
Did not know I can pass types to Ramda functions great! thanks a lot for it.