Skip to content

Infer operator returning container type instead of applied genericΒ #48772

Closed
@kschat

Description

@kschat

Bug Report

πŸ”Ž Search Terms

infer, conditional type, generic, alias

πŸ•— Version & Regression Information

  • This changed between versions v4.1.5 and v4.2.3

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type BaseContext<TConfig> = {
  foo: number;
  config: TConfig;
};

type FullContext<TConfig, TContext> = TContext & BaseContext<TConfig>;

type ExtractAdditionalContext<TContext extends FullContext<any, any>> =
  TContext extends FullContext<any, infer TAdditionalContext>
    ? TAdditionalContext
    : never;

type Config = Record<string, string>;
type AdditionalContext = { customValue: string };

type Context = FullContext<Config, AdditionalContext>;
type ExtractedAdditionalContext = ExtractAdditionalContext<Context>;

declare const additionalContext: AdditionalContext;
const test1: ExtractedAdditionalContext = additionalContext;

πŸ™ Actual behavior

I expected ExtractedAdditionalContext to be AdditionalContext or { customValue: string }, and for test1 to compile without error.

πŸ™‚ Expected behavior

ExtractedAdditionalContext is AdditionalContext & BaseContext<Config> which is the same type as Context. test1 results in a compiler error of:

Type 'AdditionalContext' is not assignable to type 'AdditionalContext & BaseContext<Config>'.
 Type 'AdditionalContext' is missing the following properties from type 'BaseContext<Config>': foo, config

Additional notes

When I remove the config property from BaseContext the issue is resolved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions