Closed
Description
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
Type
Projects
Relationships
Development
No branches or pull requests
Activity
mhegazy commentedon Oct 25, 2017
Same issue referenced in
Partial
andReadonly
are not commutative when using generics #17682mhegazy commentedon 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.
DanielRosenwasser commentedon 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 commentedon Dec 4, 2017
@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 commentedon 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.