Skip to content

Cannot define a Partial<T> for a constrained T extends Base specifying only members of Base #12799

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
pzavolinsky opened this issue Dec 9, 2016 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@pzavolinsky
Copy link

pzavolinsky commented Dec 9, 2016

TypeScript Version: 2.1.4

Code

interface Base {
  page: number
}

function test<T extends Base>() {
    const firstPage:Partial<T> = { page: 1 };
}

Also reproducible here.

Expected behavior:
firstPage should be accepted as a valid partial instance of T.

Actual behavior:

error TS2322: Type '{ page: 1; }' is not assignable to type 'Partial<T>'.

Also, the error is not very helpful explaining why the type is not assignable.

@pzavolinsky
Copy link
Author

Related to #12731.

I believe this should be considered a bug rather than a suggestion (as the issue above).

@RyanCavanaugh RyanCavanaugh added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Dec 13, 2016
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 31, 2017

Duplicate of #16356 and #19388

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs Investigation This issue needs a team member to investigate its status. labels Oct 31, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 31, 2017

Use Partial<Base> instead.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants