Skip to content

Conversation

@colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Jul 17, 2023

As discussed in alphagov/govuk-frontend#3971 (comment) @prettier/sync doesn't support named exports:

import { format } from '@prettier/sync'

This PR updates the type declarations to show that

I've also updated the tsconfig.json file so local test.js imports are checked too

Named exports not allowed

test.js Outdated
fileURLToPath(fakePrettierUrl),
]) {
test(prettierEntry, async () => {
test(prettierEntry.toString(), async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler flagged this line because test() only accepts string not URL

Copy link
Contributor

@remcohaszing remcohaszing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you’re trying to do, but I’m not sure if there is a proper way to do this correctly.

Interestingly, this works, but it relies on errors in the local type definitions:

// @ts-expect-error
declare const synchronizedPrettier: SynchronizedPrettier;

// @ts-expect-error
declare namespace synchronizedPrettier {
  function createSynchronizedPrettier(options: {
    prettierEntry: string | URL;
  }): SynchronizedPrettier
}

@colinrotherham colinrotherham marked this pull request as draft July 17, 2023 16:18
@colinrotherham colinrotherham marked this pull request as ready for review July 17, 2023 19:53
Updates types to show that `createSynchronizedPrettier` is the only ESM named export to ensure TypeScript throws errors for invalid named exports such as:

```
import { format } from '@prettier/sync'
```
@fisker fisker merged commit 9a2de4d into prettier:main Jun 8, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants