From 3b4aced06427fc6111f334ea8b4d00a5b949fdc6 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Tue, 6 Jan 2026 09:36:54 +0000 Subject: [PATCH] fix(formatter): should not treat multi-type arguments of TSTypeReference as a complex type (#17708) **Input:** ```tsx // Non-complex type arguments, as none of the type arguments of Record is a complex type. const result = configurationService.getValue>( enalementSetting ); ``` **Before output:** ```tsx // Non-complex type arguments, as none of the type arguments of Record is a complex type. const result = configurationService.getValue< Record >(enalementSetting); ``` [Prettier Playground](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEAdKB6DACActAWkgFsAHAGzgA9sYBPUubAQwCcBzAV2IRgGcANCz7Yo0JhABmtABZN6jFh268RU7ACU4kVgBNsASxHNsJCtVoM4AOnSQofGNlZw+nck4C8p6JINdWZhgDaABlOFYANwMwG3Y4GAA1ZnJOOAAeLR1ddMdWAyh2IQAjCAhKZigAPiqACnRsbAQUuB5YcJhgwvQASgBuEAEQCFJg6D5kUDZWCAB3AAU2BAmUFNnmOgmh4sCwAGsE0OYeABkCuGRJFL44IYhigCttGAB1QNJkEFIXG6iL7d2BxgoVIzDABXYyBgrDSQxuxAMUJhtxA1EY+TaMBSAHl0UEIKx5hA+AYxlBPghdINUVR0QZMSkACoRKBsAyuS7XFEkwqUACKnAg8E55BuQwefCooQh-MFwqQV1FKIAjnK4PMZqQViBmHwCFA4HBdEbqdDmAZyBCAMIQYjEZifFLkak89iUACCnXyxU48HmETOBpFYpAMhgxHILxkpNcoNi4QcpIM0XonzAfC2IEiaQAklBje0wPlRu786F6JRgyjvsS4G9mB8UN9XBFIv9UfnsZJAxcUORJNSCr8YBrmOx7VWhqDWL9PsVmMU4OQCPxqd8Cq8DLoYDJkAAOAAMQxcqoMLlH44dCq5QyxxReW53yAATENODdGQuVoqQ61F7pjV0E5Ki4Mc4AAMQJe1OghR1fQgEAAF9EKAA) **After output:** ```tsx // Non-complex type arguments, as none of the type arguments of Record is a complex type. const result = configurationService.getValue>(enalementSetting); ``` --- crates/oxc_formatter/src/utils/assignment_like.rs | 2 +- .../ts/assignments/complex-type-arguments.ts | 5 +++++ .../ts/assignments/complex-type-arguments.ts.snap | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/oxc_formatter/src/utils/assignment_like.rs b/crates/oxc_formatter/src/utils/assignment_like.rs index d3275087264c0..baa0ab07a3a42 100644 --- a/crates/oxc_formatter/src/utils/assignment_like.rs +++ b/crates/oxc_formatter/src/utils/assignment_like.rs @@ -1027,7 +1027,7 @@ fn is_complex_type_arguments(type_arguments: &TSTypeParameterInstantiation) -> b if let TSType::TSTypeReference(type_ref) = first_argument && let Some(type_args) = &type_ref.type_arguments { - return is_complex_type_arguments(type_args); + return type_args.params.iter().any(is_complex_ts_type); } false diff --git a/crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts b/crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts index d4650dcc833b5..77fe2e8c044b5 100644 --- a/crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts +++ b/crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts @@ -18,3 +18,8 @@ export class Test { }> >(); } + +// Non-complex type arguments, as none of the type arguments of Record is a complex type. +const result = configurationService.getValue>( + enalementSetting +); diff --git a/crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts.snap index 5207583918ff9..2b7e90aa2e3dc 100644 --- a/crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts.snap +++ b/crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts.snap @@ -23,6 +23,11 @@ export class Test { >(); } +// Non-complex type arguments, as none of the type arguments of Record is a complex type. +const result = configurationService.getValue>( + enalementSetting +); + ==================== Output ==================== ------------------ { printWidth: 80 } @@ -48,6 +53,10 @@ export class Test { >(); } +// Non-complex type arguments, as none of the type arguments of Record is a complex type. +const result = + configurationService.getValue>(enalementSetting); + ------------------- { printWidth: 100 } ------------------- @@ -72,4 +81,7 @@ export class Test { >(); } +// Non-complex type arguments, as none of the type arguments of Record is a complex type. +const result = configurationService.getValue>(enalementSetting); + ===================== End =====================