Declare createSynchronizedPrettier as only named export#12
Merged
Conversation
Includes type discovery and autocomplete in `test.js` too
For example Prettier uses `export {}`
colinrotherham
commented
Jul 17, 2023
| fileURLToPath(fakePrettierUrl), | ||
| ]) { | ||
| test(prettierEntry, async () => { | ||
| test(prettierEntry.toString(), async () => { |
Contributor
Author
There was a problem hiding this comment.
The compiler flagged this line because test() only accepts string not URL
remcohaszing
suggested changes
Jul 17, 2023
remcohaszing
left a comment
Contributor
There was a problem hiding this comment.
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
}867d27c to
bb011b8
Compare
fisker
reviewed
Jul 17, 2023
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'
```
bb011b8 to
308ba4c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As discussed in alphagov/govuk-frontend#3971 (comment)
@prettier/syncdoesn't support named exports:This PR updates the type declarations to show that
I've also updated the tsconfig.json file so local
test.jsimports are checked too