Skip to content

Proposal: SubType #22

@rifler

Description

@rifler
 type SubType<Base, Condition> = Pick<
     Base,
     {
         [Key in keyof Base]: Base[Key] extends Condition ? Key : never
     }[keyof Base]
 >;

Examples:

var object = {
    a: 1,
    b: true,
    c: () => null,
    d: () => null,
};

type JustMethods = SubType<typeof object, (...args: unknown[]) => unknown>;
// { c: () => null, d: () => null }

JustMethods from #4 can be realized via SubType. But, as I understand, JustProps can't. Maybe it will be possible after microsoft/TypeScript#29317

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