prettier / prettier-synchronized

Synchronous version of Prettier
MIT License
24 stars 7 forks source link

Check type declarations with JSDoc comments #10

Closed colinrotherham closed 1 year ago

colinrotherham commented 1 year ago

Great work on Prettier v3 🙌

Hope this PR is welcome, but I've added JSDoc + tsconfig.json to export type declarations

I followed the link in the Prettier 3.0: Hello, ECMAScript Modules! blog post after realising that the Prettier sync APIs would still be needed to avoid Nunjucks template changes for asynchronous rendering 😣

If you still need sync APIs, you can try @prettier/sync

I'd be happy to make any tweaks, and wasn't sure if committing the types would be preferred

Closes: https://github.com/prettier/prettier-synchronized/issues/8

fisker commented 1 year ago

Thanks for working on this. Can it be done by adding a .d.ts file?

colinrotherham commented 1 year ago

Thanks for working on this. Can it be done by adding a .d.ts file?

Yeah course, I've pushed up a new .gitignore to show them:

  1. Added index.d.cts type declarations for .cjs extension files
  2. Added index.d.cts.map type declaration map to link back to source

Declaration Map Generates a source map for .d.ts files which map back to the original .ts source file. This will allow editors such as VS Code to go to the original .ts file when using features like Go to Definition.

I've used import('prettier') in the JSDoc to make sure the existing type declarations are reused when built

Imports types from Prettier
fisker commented 1 year ago

I have no experience with type declarations.

@SimenB Can you help review?

colinrotherham commented 1 year ago

@fisker I've removed all the unnecessary autogenerated lines from index.d.cts

We're left with the good stuff like Awaited<ReturnType<Prettier[FunctionName]>>

But I've kept the tsconfig.json and JSDoc comments so you get type checking locally too

fisker commented 1 year ago

Thank you @colinrotherham

Released https://github.com/prettier/prettier-synchronized/releases/tag/v0.3.0

colinrotherham commented 1 year ago

Brilliant, thanks @fisker

Just a reminder that manually adding the types without a type declaration map means editor and IDE "Go to definition" will jump to the types rather than the original Prettier source code, should you want that in future

Glad I could help though, appreciate it