microsoft / microsoft/TypeScript

Type bug: using mapped type (Partial) & this type & lookup type

Open
#36,505 3 comments 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.