diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 725cdf4e8e493..72ae06a2df451 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13903,7 +13903,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function isConstTypeVariable(type: Type | undefined, depth = 0): boolean { return depth < 5 && !!(type && ( type.flags & TypeFlags.TypeParameter && some((type as TypeParameter).symbol?.declarations, d => hasSyntacticModifier(d, ModifierFlags.Const)) || - type.flags & TypeFlags.Union && some((type as UnionType).types, t => isConstTypeVariable(t, depth)) || + type.flags & TypeFlags.UnionOrIntersection && some((type as UnionOrIntersectionType).types, t => isConstTypeVariable(t, depth)) || type.flags & TypeFlags.IndexedAccess && isConstTypeVariable((type as IndexedAccessType).objectType, depth + 1) || type.flags & TypeFlags.Conditional && isConstTypeVariable(getConstraintOfConditionalType(type as ConditionalType), depth + 1) || type.flags & TypeFlags.Substitution && isConstTypeVariable((type as SubstitutionType).baseType, depth) || diff --git a/tests/baselines/reference/typeParameterConstModifiersWithIntersection.symbols b/tests/baselines/reference/typeParameterConstModifiersWithIntersection.symbols new file mode 100644 index 0000000000000..515988a8186ee --- /dev/null +++ b/tests/baselines/reference/typeParameterConstModifiersWithIntersection.symbols @@ -0,0 +1,56 @@ +//// [tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiersWithIntersection.ts] //// + +=== typeParameterConstModifiersWithIntersection.ts === +// https://github.com/microsoft/TypeScript/issues/55778 + +interface Config { +>Config : Symbol(Config, Decl(typeParameterConstModifiersWithIntersection.ts, 0, 0)) +>T1 : Symbol(T1, Decl(typeParameterConstModifiersWithIntersection.ts, 2, 17)) +>type : Symbol(type, Decl(typeParameterConstModifiersWithIntersection.ts, 2, 29)) + + useIt: T1; +>useIt : Symbol(Config.useIt, Decl(typeParameterConstModifiersWithIntersection.ts, 2, 47)) +>T1 : Symbol(T1, Decl(typeParameterConstModifiersWithIntersection.ts, 2, 17)) +} + +declare function test< +>test : Symbol(test, Decl(typeParameterConstModifiersWithIntersection.ts, 4, 1)) + + T1 extends { type: string }, +>T1 : Symbol(T1, Decl(typeParameterConstModifiersWithIntersection.ts, 6, 22)) +>type : Symbol(type, Decl(typeParameterConstModifiersWithIntersection.ts, 7, 14)) + + const TConfig extends Config, +>TConfig : Symbol(TConfig, Decl(typeParameterConstModifiersWithIntersection.ts, 7, 30)) +>Config : Symbol(Config, Decl(typeParameterConstModifiersWithIntersection.ts, 0, 0)) +>T1 : Symbol(T1, Decl(typeParameterConstModifiersWithIntersection.ts, 6, 22)) + +>(config: { produceThing: T1 } & TConfig): TConfig; +>config : Symbol(config, Decl(typeParameterConstModifiersWithIntersection.ts, 9, 2)) +>produceThing : Symbol(produceThing, Decl(typeParameterConstModifiersWithIntersection.ts, 9, 11)) +>T1 : Symbol(T1, Decl(typeParameterConstModifiersWithIntersection.ts, 6, 22)) +>TConfig : Symbol(TConfig, Decl(typeParameterConstModifiersWithIntersection.ts, 7, 30)) +>TConfig : Symbol(TConfig, Decl(typeParameterConstModifiersWithIntersection.ts, 7, 30)) + +const result = test({ +>result : Symbol(result, Decl(typeParameterConstModifiersWithIntersection.ts, 11, 5)) +>test : Symbol(test, Decl(typeParameterConstModifiersWithIntersection.ts, 4, 1)) + + produceThing: {} as { +>produceThing : Symbol(produceThing, Decl(typeParameterConstModifiersWithIntersection.ts, 11, 21)) + + type: "foo"; +>type : Symbol(type, Decl(typeParameterConstModifiersWithIntersection.ts, 12, 23)) + + }, + useIt: { +>useIt : Symbol(useIt, Decl(typeParameterConstModifiersWithIntersection.ts, 14, 4)) + + type: "foo", +>type : Symbol(type, Decl(typeParameterConstModifiersWithIntersection.ts, 15, 10)) + + }, + extra: 10, +>extra : Symbol(extra, Decl(typeParameterConstModifiersWithIntersection.ts, 17, 4)) + +}); diff --git a/tests/baselines/reference/typeParameterConstModifiersWithIntersection.types b/tests/baselines/reference/typeParameterConstModifiersWithIntersection.types new file mode 100644 index 0000000000000..ac817e3200422 --- /dev/null +++ b/tests/baselines/reference/typeParameterConstModifiersWithIntersection.types @@ -0,0 +1,52 @@ +//// [tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiersWithIntersection.ts] //// + +=== typeParameterConstModifiersWithIntersection.ts === +// https://github.com/microsoft/TypeScript/issues/55778 + +interface Config { +>type : string + + useIt: T1; +>useIt : T1 +} + +declare function test< +>test : >(config: { produceThing: T1;} & TConfig) => TConfig + + T1 extends { type: string }, +>type : string + + const TConfig extends Config, +>(config: { produceThing: T1 } & TConfig): TConfig; +>config : { produceThing: T1; } & TConfig +>produceThing : T1 + +const result = test({ +>result : { readonly produceThing: { type: "foo"; }; readonly useIt: { readonly type: "foo"; }; readonly extra: 10; } +>test({ produceThing: {} as { type: "foo"; }, useIt: { type: "foo", }, extra: 10,}) : { readonly produceThing: { type: "foo"; }; readonly useIt: { readonly type: "foo"; }; readonly extra: 10; } +>test : >(config: { produceThing: T1; } & TConfig) => TConfig +>{ produceThing: {} as { type: "foo"; }, useIt: { type: "foo", }, extra: 10,} : { produceThing: { type: "foo"; }; useIt: { type: "foo"; }; extra: 10; } + + produceThing: {} as { +>produceThing : { type: "foo"; } +>{} as { type: "foo"; } : { type: "foo"; } +>{} : {} + + type: "foo"; +>type : "foo" + + }, + useIt: { +>useIt : { type: "foo"; } +>{ type: "foo", } : { type: "foo"; } + + type: "foo", +>type : "foo" +>"foo" : "foo" + + }, + extra: 10, +>extra : 10 +>10 : 10 + +}); diff --git a/tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiersWithIntersection.ts b/tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiersWithIntersection.ts new file mode 100644 index 0000000000000..a3ea303694e68 --- /dev/null +++ b/tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiersWithIntersection.ts @@ -0,0 +1,23 @@ +// @strict: true +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/55778 + +interface Config { + useIt: T1; +} + +declare function test< + T1 extends { type: string }, + const TConfig extends Config, +>(config: { produceThing: T1 } & TConfig): TConfig; + +const result = test({ + produceThing: {} as { + type: "foo"; + }, + useIt: { + type: "foo", + }, + extra: 10, +}); \ No newline at end of file