Skip to content

Mapped types with direct and aliased keyof usage #12602

Closed

Description

TypeScript Version: master (fc1f6e3)

Code

type X = {
  a?: any;
  b: any;
}

type Keys = keyof X;

type Direct = {
  [K in keyof X]: any;
}
// type Direct = {
//   a?: any; - optional
//   b: any;
// }

type WithAlias = {
  [K in Keys]: any;
}
// type WithAlias = {
//   a: any; - required
//   b: any;
// }

Expected behavior:
Types Direct and WithAlias have the same a property. I think that a property must be required in both Direct and WithAlias types.

Actual behavior:
Types Direct and WithAlias have different a property (optional and required).

Activity

  1. ahejlsberg commented on Dec 1, 2016

    @ahejlsberg
    Member

    This is working as intended. See #12563.

  2. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions