diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 6cc654453e41b..5539a8e30cb2d 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -326,8 +326,9 @@ namespace ts.formatting { export function argumentStartsOnSameLineAsPreviousArgument(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean { if (isCallOrNewExpression(parent)) { if (!parent.arguments) return false; - - const currentNode = Debug.assertDefined(find(parent.arguments, arg => arg.pos === child.pos)); + const currentNode = find(parent.arguments, arg => arg.pos === child.pos); + // If it's not one of the arguments, don't look past this + if (!currentNode) return false; const currentIndex = parent.arguments.indexOf(currentNode); if (currentIndex === 0) return false; // Can't look at previous node if first diff --git a/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts b/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts new file mode 100644 index 0000000000000..8567a5ff06d68 --- /dev/null +++ b/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts @@ -0,0 +1,18 @@ +/// + +////const genericObject = new GenericObject< +//// /*1*/{} +////>(); +////const genericObject2 = new GenericObject2< +//// /*2*/{}, +//// /*3*/{} +////>(); + +format.document(); + +goTo.marker("1"); +verify.currentLineContentIs(" {}"); +goTo.marker("2"); +verify.currentLineContentIs(" {},"); +goTo.marker("3"); +verify.currentLineContentIs(" {}"); \ No newline at end of file