Skip to content
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

'Foo' is not assignable to 'Partial<T>' where generic 'T extends Foo' #19467

Closed
GregorioBR opened this issue Oct 25, 2017 · 4 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@GregorioBR
Copy link

TypeScript Version: 2.5.3

Code

interface IViewState {
    data?: string;
}

class View<S extends IViewState> {

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

Expected behavior:

Code to compile

Actual behavior:

C:\Users\Greg\Desktop\demo-app\greg>tsc --version
Version 2.5.3

C:\Users\Greg\Desktop\demo-app\greg>tsc --init
message TS6071: Successfully created a tsconfig.json file.

C:\Users\Greg\Desktop\demo-app\greg>tsc
test.ts(12,9): error TS2322: Type '{ data: string; }' is not assignable to type 'Partial<S>'.
@DanielRosenwasser
Copy link
Member

Hey, thanks for filing, but this seems to be a duplicate of #19388, a duplicate of #17071, and a duplicate of #13442

In the future using the issue tracker's search functionality can make it easier for us to triage issues. Thanks!

@DanielRosenwasser DanielRosenwasser changed the title Generics with 'extends' invalid type assertion Generic 'T' with 'extends Foo' is not assignable to 'Partial<Foo>' Oct 25, 2017
@DanielRosenwasser DanielRosenwasser changed the title Generic 'T' with 'extends Foo' is not assignable to 'Partial<Foo>' 'Foo' is not assignable to 'Partial<T>' where generic 'T extends Foo' Oct 25, 2017
@DanielRosenwasser
Copy link
Member

However, I did try using a type assertion which your example doesn't use and that is indeed an error. I've filed #19470 for you there.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Oct 25, 2017
@GregorioBR
Copy link
Author

Thank you very much!

@mhegazy
Copy link
Contributor

mhegazy commented Nov 9, 2017

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

@mhegazy mhegazy closed this as completed Nov 9, 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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants