Skip to content

Printer doesn't parenthesize untyped rest arguments in function type literals #15651

@DanielRosenwasser

Description

@DanielRosenwasser

TypeScript Version: 2.3.2

Code

import ts = require("typescript");

function getAnyFunctionTypeNode() {
    const param = ts.createParameter(
        /*decorators*/ undefined,
        /*modifiers*/ undefined,
        ts.createToken(ts.SyntaxKind.DotDotDotToken),
        "args");

    const result = ts.createFunctionTypeNode(
            /*typeParameters*/ undefined,
            /*parameters*/[param],
            /*type*/ ts.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword));
    return result;
}

const node = getAnyFunctionTypeNode();
const file = ts.createSourceFile("foo.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
const output = ts.createPrinter().printNode(ts.EmitHint.Unspecified, node, file);
console.log(output);

Expected behavior:

Console logs the following:

(...args) => any

Actual behavior:

Console logs the following:

...args => any

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: APIRelates to the public API for TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions