Skip to content

Real world usage of omit is now awkward #108

@robations

Description

@robations

I think the types of omit have been strengthened recently as (since minor upgrades to v0.29) I have a number of type errors that are flagged, especially for omit.

If you have a function signature, you may omit certain object keys in the sense, "I'm only interested in a subtype". This allows, say, unit tests to be more minimal and aligns with the principle of least knowledge. But in usage, the omitted keys may be present and you may want to acknowledge this in the implementation.

I'm not sure this is the most minimal example, but I hope shows what I mean:

import R from "ramda";

export interface Params {
    foo: string;
    bar?: string;
}

export function fn1(f: typeof fn2) {
    return (params: Omit<Params, "bar">) => {
        // imagine this omission is an important use case
        return f(R.omit(["bar"] as const, params)); // TS2322
    };
}

function fn2({ foo, bar }: Params): boolean {
    return false;
}

const a: Params = {foo: "foo", bar: "bar"};

fn1(fn2)(a);

See also TS Playground link

In other words, I would expect seemingly unrelated keys not to be a type error. I can probably work around this by creating my own omit implementation, but this goes against the spirit of ramda being a useful multi-tool library when I can't actually use it in a multitude of cases.

I can already hear gnashing of teeth, because probably someone has worked hard to add the new types. Of course, I can see the opposite argument that the strong typing will flag up potential typos.

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