Skip to content

formatter: export default (fn as T) loses outer parens, breaking the type assertion #23501

Description

@BenGearset

Input

interface Foo {}

export default (function foo(this: Foo, x: number) {
    const self = this;
    return self;
} as unknown as new (x: number) => Foo);

Oxfmt output (version 0.55.0)

interface Foo {}

export default function foo(this: Foo, x: number) {
  const self = this;
  return self;
} as unknown as new (x: number) => Foo;

Playground link

The outer parentheses here are load-bearing. Without them, the right-hand side of export default parses as a function declaration rather than a function expression, so the trailing as unknown as new (...) => Foo is no longer attached to anything. Downstream code that does new defaultExport(...) then fails with TS7009 ("new expression, whose target lacks a construct signature").

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions