Skip to content

Mapped types with direct and aliased keyof usage #12602

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

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