diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index c8efe863c1344..577cba5e01a7d 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -23100,14 +23100,22 @@ func (c *Checker) instantiateTypeWorker(t *Type, m *TypeMapper, alias *TypeAlias } types := source.Types() newTypes := c.instantiateTypes(types, m) - if core.Same(newTypes, types) && alias.Symbol() == t.alias.Symbol() { - return t - } if alias == nil { alias = c.instantiateTypeAlias(t.alias, m) } + intersectionFlags := IntersectionFlagsNone + if core.Same(newTypes, types) { + if alias.Symbol() == t.alias.Symbol() && slices.Equal(alias.TypeArguments(), t.alias.TypeArguments()) { + return t + } + // Only the alias changed, as in an alias that doesn't reference its type parameters. The constituents + // of an intersection are already reduced, so don't reduce again; that would drop the {} in `string & {}`. + if t.flags&TypeFlagsIntersection != 0 { + intersectionFlags = IntersectionFlagsNoSupertypeReduction + } + } if source.flags&TypeFlagsIntersection != 0 { - return c.getIntersectionTypeEx(newTypes, IntersectionFlagsNone, alias) + return c.getIntersectionTypeEx(newTypes, intersectionFlags, alias) } return c.getUnionTypeEx(newTypes, UnionReductionLiteral, alias, nil /*origin*/) case flags&TypeFlagsIndex != 0: diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitUnusedAliasTypeParameter.js b/tsc/testdata/baselines/reference/compiler/declarationEmitUnusedAliasTypeParameter.js new file mode 100644 index 0000000000000..6e6a1ebf9582f --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitUnusedAliasTypeParameter.js @@ -0,0 +1,100 @@ +//// [tests/cases/compiler/declarationEmitUnusedAliasTypeParameter.ts] //// + +//// [types.ts] +export type Labeled