Skip to content

Type inference regression due to circular type definition #36220

@ashi009

Description

@ashi009

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs InvestigationThis issue needs a team member to investigate its status.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions