Skip to content

Broken inference for generic classes passed to a generic function taking an optional class #61633

@LukeAbby

Description

@LukeAbby

🔎 Search Terms

class inference, optional class, broken inference

🕗 Version & Regression Information

This changed in PR #31116

However, this was the first time that there was even a distinction between a generic and non-generic class during inference to my knowledge. This likely means this has existed ever since the ability to infer a generic class has existed.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAggdiAwgezgZ2AJwK4GNjKZQC8UcEA7lABQB09AhpgOZoBcUDCA2gLoCUJAHxRkAIwBWEfAG4AUHIBm2OPgCWqKACUIcACYRMAMQA2DVgFk1ADzVwAPACEGaCIjNo0UCNeC69XvBIqBg4+IRQAD5QKgaKdhB6JDH6EPHkekLUclC5UM6uAPwcBW4eaAA0coIA3gC+8nK45VAocMAMCZj2ACoi9Qo6qcZmljZ21G0dXfxyAPRzeUvLeQB6sCzYALa6wKKKUKCQUADkRxDIB1Od5JgnUGpecMh7LmhqzHAMYibQBFBgJgMHZ+IiXQ7gaAnWJpBJ6E60IA

💻 Code

type AnyConstructor = new (...args: any[]) => object;

function RenderFlagsMixin<BaseClass extends AnyConstructor | undefined = undefined>(
    Base?: BaseClass,
) {};

class Container<T> {}
//             ^ Only happens when the class is generic.

RenderFlagsMixin(Container)
//               ^ Argument of type 'typeof Container' is not assignable to parameter of type 'undefined'.

🙁 Actual behavior

BaseClass is inferred as undefined despite the call being the value Container.

🙂 Expected behavior

BaseClass should be inferred as typeof Container.

Additional information about the issue

No response

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy