Skip to content

Can't partial a generic type with extension constraint #13442

Closed
@markboyall

Description

@markboyall

TypeScript Version: 2.1.5

export function apply<T>(existing: T) {
    return {
        changes: (changes: Partial<T>): T => {
            return null;
        }
    };
}

function applyVisibility<SectionVisibility, Document extends { sectionVisibility: SectionVisibility }>(document: Document, visibilityUpdates: SectionVisibility): Document {
    const sectionVisibility = apply(document.sectionVisibility).changes(visibilityUpdates);
    return apply(document).changes({ sectionVisibility: sectionVisibility });
}

Expected behavior:

Compiles.

Actual behavior:

Doesn't compile. The type { sectionVisibility: SectionVisibility } is not assignable to Partial, despite the fact that we clearly constrained Document to include this property, and it's Partial so we know that every other property is optional.

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