Skip to content

Mapped type optional -> required property issue #13224

Closed
@JakeGinnivan

Description

@JakeGinnivan

TypeScript Version: 2.1.4

Code
https://github.com/JakeGinnivan/TypeScriptMappedTypeIssue

Expected behavior:
The mapped type

export type PropDescriptions<T> = {
    [P in keyof T]: string
}

Is marking all the properties as required, I would expect this to fail:

interface ThingProps {
    prop1: string
    prop2?: string
}

const expected: PropDescriptions<ThingProps> = {
    prop1: 'Ok'
}

with Property 'prop2' is missing in type {...}

Actual behavior:
No compilation error

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