Skip to content

Generic types wrapped with Partial cannot be assigned to empty objects #13908

@JustASquid

Description

@JustASquid

TypeScript Version: 2.1.4

Code

interface I {
	a: string;
}

function f1<T extends Partial<I>>() {
	// Error TS2322
	let i: T = {};
}

function f2<T extends I>() {
	// Error TS2322
	let i: Partial<T> = {};
}

Expected behavior:
No errors

Actual behavior:
Error TS2322: Type '{}' is not assignable to type 'T' / 'Partial'

Forgive me if this is simply a limitation of the Typescript engine and the implementation of Partial, but I don't know enough about the internals to make a judgement there.

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