Skip to content

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

@DanielRosenwasser

Description

@DanielRosenwasser

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" }.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions