Skip to content

Conditional types break with property chaining #32735

Open
@AnyhowStep

Description

@AnyhowStep

TypeScript Version: 3.5.1

Search Terms:

property chaining, generic, object type param, conditional type

Code

Modified version of @fatcerberus ' attempt to break TS.

type Droste<T extends {x:number|string}> = {
    value: T,
    /**
     * Should alternate between string and number
     */
    droste: Droste<{x:(T["x"] extends number ? string : number)}>
};

declare const droste: Droste<{x:number}>;

//number
const _0 = droste.droste.droste.droste.droste.droste.droste.droste.droste.droste.droste
    .droste.droste.droste.droste.droste.droste.droste.droste.droste.droste
    .droste.droste;
const _1 = _0.droste; //string
const _2 = _1.droste; //number
const _3 = _2.droste; //string

const _4 = _3.droste; //Expected number, actual string, ???
const _5 = _4.droste; //string
const _6 = _5.droste; //string
const _7 = _6.droste; //string
const _8 = _7.droste; //string
const _9 = _8.droste; //string
//string forever and ever. Where is `number`?

Expected behavior:

Each access to .droste should alternate between string and number.
Or give a max instantiation depth/count error.

Actual behavior:

It alternates between string and number and then breaks after while.
From that point, it just sticks with string.

No errors given.

Playground Link:

Playground

Related Issues:

It is similar to #32707
Except, it gives up and resolves the type to string, rather than any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions