Input
Found in sveltejs/svelte repo.
File: packages/svelte/src/internal/client/dom/css.js
var target = /** @type {ShadowRoot} */ (root).host
? /** @type {ShadowRoot} */ (root)
: /** @type {Document} */ (root).head ?? /** @type {Document} */ (root.ownerDocument).head;
Config
Oxfmt output
var target = /** @type {ShadowRoot} */ (root).host
? /** @type {ShadowRoot} */ (root)
: /** @type {Document} */ ((root).head ?? /** @type {Document} */ (root.ownerDocument).head);
Prettier output
Prettier version: 3.9.5
var target = /** @type {ShadowRoot} */ root.host
? /** @type {ShadowRoot} */ root
: /** @type {Document} */ (root.head ?? /** @type {Document} */ root.ownerDocument.head);
Additional notes
Prettier removes the parentheses required by JSDoc type casts, changing /** @type {ShadowRoot} */ (root).host to /** @type {ShadowRoot} */ root.host.
While runtime-equivalent, this breaks the casts entirely: a JSDoc cast /** @type {T} */ (expr) is only recognized when the expression is parenthesized, so after formatting the comments become plain comments and TypeScript no longer applies the types.
Oxfmt preserves the cast parentheses, but wraps the alternate branch in an extra pair of parentheses, changing /** @type {Document} */ (root).head ?? ... to /** @type {Document} */ ((root).head ?? ...). This moves the cast from root to the entire ?? expression, which changes its meaning at the type level (the original casts root to Document before accessing .head; the new form casts the result of the whole expression).
Input
Found in sveltejs/svelte repo.
File:
packages/svelte/src/internal/client/dom/css.jsConfig
{ "useTabs": true, "singleQuote": true, "trailingComma": "none", "printWidth": 100 }Oxfmt output
Prettier output
Prettier version:
3.9.5Additional notes
Prettier removes the parentheses required by JSDoc type casts, changing
/** @type {ShadowRoot} */ (root).hostto/** @type {ShadowRoot} */ root.host.While runtime-equivalent, this breaks the casts entirely: a JSDoc cast
/** @type {T} */ (expr)is only recognized when the expression is parenthesized, so after formatting the comments become plain comments and TypeScript no longer applies the types.Oxfmt preserves the cast parentheses, but wraps the alternate branch in an extra pair of parentheses, changing
/** @type {Document} */ (root).head ?? ...to/** @type {Document} */ ((root).head ?? ...). This moves the cast fromrootto the entire??expression, which changes its meaning at the type level (the original castsroottoDocumentbefore accessing.head; the new form casts the result of the whole expression).