Skip to content

Partial not properly inferred from generic types #12731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fongandrew opened this issue Dec 7, 2016 · 2 comments
Closed

Partial not properly inferred from generic types #12731

fongandrew opened this issue Dec 7, 2016 · 2 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@fongandrew
Copy link

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?

@TomerKr
Copy link

TomerKr commented May 16, 2017

I think this should be changed to a bug rather than a suggestion, as you could expect this work in cases such as the above linked issues.

@RyanCavanaugh
Copy link
Member

These work as expected now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants