-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Description
Summary
assoc sometimes returns a more narrow type than what is passed to it. Since assoc never removes props, this feels wrong from a type perspective. I would expect assoc to only add or modify props, never remove.
In the example below, a complex type with 2 props is typed as Record<'flag', bool> after passing through assoc
Dependencies
ramda@0.29.0@types/ramda@0.29.1typescript@5.0.2
Example
import { assoc } from "ramda";
type OriginalType = {
name: string;
flag: boolean;
};
function takesAnOriginalType(original: OriginalType) {
console.log(original);
}
const array: OriginalType[] = [{ name: "test", flag: true }];
const mapped = array.map(assoc("flag", false));
takesAnOriginalType(mapped);
^^^^^^Error
const mapped: Record<"flag", boolean>[]
Argument of type 'Record<"flag", boolean>[]' is not assignable to parameter of type 'OriginalType'.
Type 'Record<"flag", boolean>[]' is missing the following properties from type 'OriginalType': name, flagts(2345)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels