microsoft / microsoft/TypeScript

Type inference regression due to circular type definition

Open
#36,220 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.8.0-dev.20200115

Search Terms:
circular type

Code

Replace

type DeepPartial<T> =
    T extends Message ? PartialMessage<T> :
    T;

type PartialMessage<T extends Message> = { [K in keyof T]?: DeepPartial<T[K]> };

with

type DeepPartial<T> =
    T extends Message ? { [K in keyof T]?: DeepPartial<T[K]> } :
    T;

Expected behavior:

Both works.

Actual behavior:

Type 'typeof SubMessage' is not assignable to type 'FieldValueType<SubMessage>'.
  The types returned by 'from(...)' are incompatible between these types.
    Property 'n' is missing in type 'Message' but required in type 'SubMessage'.(2322)

Playground Link:

Without circular type definition

With circular type definition

Related Issues:

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.

Research direction

Start by reproducing the two Playground examples with TypeScript 3.8.0-dev.20200115, then check whether the issue still occurs in the latest published version or typescript@next. Done means the circular and non-circular DeepPartial definitions both type-check without the reported assignability error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.