Skip to content

Ugly formatting for Typescript generic type type assertion #4171

@ethanresnick

Description

@ethanresnick

Prettier 1.11.1
Playground link

--parser typescript

Input:

function y() {
  const finalConfiguration =
    <Immutable.Map<string, any>>someExistingConfigMap.mergeDeep(fallbackOpts);
          
  if(true) {
    const finalConfiguration =
      <Immutable.Map<string, any>>someExistingConfigMap.mergeDeep(fallbackOptions);
  }
}

Output:

function y() {
  const finalConfiguration = <Immutable.Map<
    string,
    any
  >>someExistingConfigMap.mergeDeep(fallbackOpts);

  if (true) {
    const finalConfiguration = <Immutable.Map<
      string,
      any
    >>someExistingConfigMap.mergeDeep(fallbackOptions);
  }
}

Expected behavior:

First assignment would be left as is. The second assignment, which can't fit on one line even with a break after the equals sign, would be rewritten to something like:

if(true) {
    const finalConfiguration = <Immutable.Map<string, any>>(
      someExistingConfigMap.mergeDeep(fallbackOptions)
   );
}

(Adding the parentheses around the expression that's subject to the type assertion is clearer, imo, than:

if(true) {
    const finalConfiguration = <Immutable.Map<string, any>>
      someExistingConfigMap.mergeDeep(fallbackOptions);

where the type assertion might be read as applying to someExistingConfigMap and not the result of mergeDeep).

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions