Skip to content

Class methods in the sources should be excluded from the resulting type of Object.entries #72

@graphemecluster

Description

@graphemecluster

Issue #56 made me think of other problems regarding the current typing of Object.entries. It might be a good chance to address them altogether.

As you know, Object.entries only copies own properties, so besides function signatures, class methods from the sources shouldn't be included in the resulting type too:

const foo = {
    method() {},
    funcProp: () => {},
};
Object.assign({}, foo); // { method, funcProp }

class Foo {
    method() {}
    funcProp = () => {};
}
Object.assign({}, new Foo()); // { funcProp }

But it's hard to determine whether a function in a class is a method or a function property. Since methods are bivariant while function properties are contravariant in TypeScript, it should be possible to distinguish between them by some tricks that determine the variance of a function, but I didn't manage to come up with a solution, so I've posted this issue instead of a PR.

As its usage seems rare, I'm not sure if it's worth spending the time to find a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions