Skip to content

Can't make mapped types with as clauses be homomorphic #40619

Closed

Description

I can't seem to find a way to make a mapped object type be homomorphic when it has an as clause.

type Getters<T> = {
    [K in keyof T as `get${capitalize string & K}`]: () => T[K]
};

interface Person {
    readonly name: string;
    age: number;
    location?: string;
}

type LazyPerson = Getters<Person>;

None of the modifiers from Person are preserved on LazyPerson. What is the right way to do this? Is there one?

Activity

  1. ahejlsberg commented on Sep 17, 2020

    @ahejlsberg
    Member

    Hmm, that's a bug. I'll work on a fix.

  2. added
    BugA bug in TypeScript
    and removed
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Sep 17, 2020
  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions