microsoft / microsoft/TypeScript
Type bug: using mapped type (Partial) & this type & lookup type
Open
@ahejlsberg is already working on this.
Since Feb 6, 2020.
Needs Investigation
Rescheduled
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: nightly
Search Terms: mapped type, Partial, this, lookup type
Code
class A {
state = { foo: "foo", bar: 42 };
something(): Partial<A["state"]> {
return { foo: "changed" }; // works
}
}
class B {
state = { foo: "foo", bar: 42 };
something(): Partial<this["state"]> {
return { foo: "changed" }; // fails
}
}
class C {
state = { foo: "foo", bar: 42 };
something(): Partial<this["state"]> {
return { foo: "changed", bar: 123 }; // works
}
}
Expected behavior:
Should type check.
Actual behavior:
Type '{ foo: "changed"; }' is not assignable to type 'Partial<this["state"]>'.(2322)
Playground Link: Example
Related Issues: Tried searching for Partial this, did not find anything related.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.