Skip to content

Mapped Type bug with modifiers #13724

Closed
Closed
@marcomura

Description

@marcomura

Putting parenthesis around the "keyof T" syntax in an inline Mapped Type, strips out the field modifier (readonly).
Without parenthesis, or defining a template using the parenthesis, this doesn't happen.

TypeScript Version: 2.1.1

Code

interface MyType {
  readonly a: number;
  b: string;
}

type MyType2 = {
  [P in keyof MyType]: MyType[P];
}

type MyType3 = {
  [P in (keyof MyType)]: MyType[P];
}

type Test<T> = {
  [P in (keyof T)]: T[P];
}
type MyType4 = Test<MyType>;

Expected behavior:
MyType2, MyType3, and MyType4 to all have the same signature.

Actual behavior:
MyType2 and MyType4 keeps the original MyType signature with modifiers.
MyType3 strips out the modifiers:

{
  a: number;
  b: string;
}

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