Skip to content

Cannot use type assertion to Partial<T> where T is generic #19470

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
DanielRosenwasser opened this issue Oct 25, 2017 · 5 comments
Closed

Cannot use type assertion to Partial<T> where T is generic #19470

DanielRosenwasser opened this issue Oct 25, 2017 · 5 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@DanielRosenwasser
Copy link
Member

In #19467, @GregorioBR filed an issue about assigning a Foo to a Partial<T> where T extends Foo.

However, in trying to solve the issue with a type assertion, I got an error:

interface State {
    data?: string;
}

class View<S extends State> {

    public processState(): Partial<S> {
      return { data: "test" } as Partial<S>;
    }
}

This is surprising because I believe Partial<S> should be comparable to { data: "test" }.

@mhegazy mhegazy added this to the TypeScript 2.7 milestone Oct 25, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 25, 2017

@ahejlsberg we chatted about this issue earlier in the week. looking through the issues, there are multiple scenarios where this comes up, and our current behavior is not desired.

@mhegazy mhegazy added the Bug A bug in TypeScript label Oct 25, 2017
@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented Oct 26, 2017

I don't think it's the same issue, but it's definitely related. This is about making it easier to say "I know what I'm doing".

@ahejlsberg
Copy link
Member

@DanielRosenwasser Looking at this, the original example compiles with no errors with the current master (and, it appears, has since 2.5) because the comparable relation is more permissive that the assignable relation.

@mhegazy The issues you reference above all have to do with assignability. Are you suggesting we change the rules there? If so, what would the new rules be?

@mhegazy
Copy link
Contributor

mhegazy commented Dec 4, 2017

I originally wanted to discuss the all as a group, and we did. I have since closed all assignebilty issues as working as intended.
It should be fine to close this one as fixed now.

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Dec 4, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants