Skip to content

Mapped type should take a function form as well #21421

Description

According to #12114 mapped types currently support following forms:

{ [ P in K ] : T }
{ [ P in K ] ? : T }
{ readonly [ P in K ] : T }
{ readonly [ P in K ] ? : T }

I think it shall also at least support a function form:

{ ([ P in K ]) : T }
{ ([ P in K ]) ? : T }
{ ([ P in K])(entities: P[], someBoolean: boolean) ? : T }

Currently Im trying to implement a Functionize<T> interface which forces implementors to implement any property of the T, but make it a function with maybe additional arguments. Example:

interface User {
     name: string;
     age: number
}

I want to do Functionize which I want to give me:

{
       name(names: string[]): string;
       age(ages: number[]): number;
}

And I'm asking about following method signature:

type Functionize<T> = {
   [P in keyof T](values: T[])?: T[P];
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions