diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 6cc654453e4..639d8f5ee44 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 its not one of the argument, dont 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 00000000000..8567a5ff06d --- /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