Skip to content

Invalid code when emitting function type signature. #27018

Closed
@Vbitz

Description

@Vbitz

TypeScript Version: 3.1.0-dev.20180907

Search Terms:
Error emitting function type signature.

Code

Note: This behavior is using the compiler API.

import * as ts from 'typescript';

const typeNode = ts.createVariableStatement(
    [], [ts.createVariableDeclaration(
            'a',
            ts.createFunctionTypeNode(
                [], [ts.createParameter([], [], undefined, 'hello')],
                ts.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)))]);

const printer = ts.createPrinter({});

console.log(printer.printNode(
    ts.EmitHint.Unspecified, typeNode,
    ts.createSourceFile('', '', ts.ScriptTarget.ES5)));

Expected behavior:
Should output:

var a: (hello) => string;

Actual behavior:

var a: hello => string;

Playground Link:

Note: This behavior is using the compiler API.

Related Issues:
I couldn't find a related issue but I think the problem is an error in https://github.com/Microsoft/TypeScript/blob/master/src/compiler/emitter.ts#L2817

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions