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").
Input
Oxfmt output (version 0.55.0)
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 (...) => Foois no longer attached to anything. Downstream code that does new defaultExport(...) then fails with TS7009 ("new expression, whose target lacks a construct signature").