Skip to content

Partial not properly inferred from generic types #12731

@fongandrew

Description

@fongandrew

TypeScript Version: 2.1.4

function test1<O>(): Partial<O> {
  return {};
}

function test2<O extends Object>(): Partial<O> {
  return {};
}

function test3<O extends {}>(): Partial<O> {
  return {};
}

Expected behavior:

No errors.

Actual behavior:

Type '{}' is not assignable to type 'Partial<O>'.


Since Partial makes every property optional, we should expect {} to be assignable to every Partial<O>, regardless of what the generic type O is.

Random speculation: Is this intended behavior because O could include required properties on its prototype that aren't on {}, even if all of the properties on O itself are optional? If that's the case, is there a way to specify that we don't care about the prototype's properties?

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions