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

Partial<T> assignability error where T extends a compatible type #19388

Closed
Ghabriel opened this issue Oct 20, 2017 · 3 comments
Closed

Partial<T> assignability error where T extends a compatible type #19388

Ghabriel opened this issue Oct 20, 2017 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Ghabriel
Copy link

TypeScript Version: 2.5.3 / playground

Code

interface Vertex {
    name: string;
}

function create<T extends Vertex>(): void {
    let x: Partial<T> = {
        name: "A"
    };
}

Expected behavior:
The code should compile, since every T will have name: string in its definition.

Actual behavior:
error TS2322: Type '{ name: "A"; }' is not assignable to type 'Partial<T>'.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Oct 20, 2017
@RyanCavanaugh
Copy link
Member

This is a correct error. create<{ name: "B" }>() is a legal call that the function body fails to fulfill correctly

@Ghabriel
Copy link
Author

The same error occurs if I change the Vertex definition to:

interface Vertex {
    name: "A";
}

In which case would the function fail with this definition?

@Ghabriel
Copy link
Author

Found it: create<{ name: null }>(). Thanks, I'll close this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants