Closed
Description
openedon Apr 19, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment