Skip to content

insertSpaceBeforeTypeAnnotation doesn't work with optional parameters / properties #25155

Closed
@jay4ay

Description

@jay4ay

This is a follow up to #19493

TypeScript Version: 2.9.2

Search Terms: insertSpaceBeforeTypeAnnotation formatter

Code

function RGBtoHSB(param1 : Int, param2?: Int, param3?: Int)
{
}

interface SquareConfig
{
    color : string;
    width?: number;
}

Expected behavior:

With insertSpaceBeforeTypeAnnotation=true, I'd expect this to be formatted as:

function RGBtoHSB(param1 : Int, param2 ?: Int, param3 ?: Int)
{
}

interface SquareConfig
{
    color : string;
    width ?: number;
}

Note the whitespace ( ) before the questionmark (?)

Actual behavior:

But it gets formatted as:

function RGBtoHSB(param1 : Int, param2?: Int, param3?: Int)
{
}

interface SquareConfig
{
    color : string;
    width?: number;
}

Playground Link: http://www.typescriptlang.org/play/#src=function%20RGBtoHSB(param1%20%3A%20Int%2C%20param2%3F%3A%20Int%2C%20param3%3F%3A%20Int)%0D%0A{%0D%0A}%0D%0A%0D%0Ainterface%20SquareConfig%0D%0A{%0D%0A%20color%20%3A%20string%3B%0D%0A%20width%3F%3A%20number%3B%0D%0A}

Related Issues: #19493 #20466

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: FormatterThe issue relates to the built-in formatterHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions