8000 docs: Suggest to use `global.ts` instead of `global.d.ts` for better compatibility with `skipLibCheck` by remcohaszing · Pull Request #1814 · amannn/next-intl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs: Suggest to use global.ts instead of global.d.ts for better compatibility with skipLibCheck #1814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025

Conversation

remcohaszing
Copy link
Contributor

Declaration files (.d.ts) are for build output. Source files (*.ts) are for source code. Declaration files are not type checked when skipLibCheck is enabled. There are legimiate use cases, but typically they should not exist outside of node_modules.

See vitejs/vite#19693

Declaration files (`.d.ts`) are for build output. Source files (`*.ts`)
are for source code. Declaration files are not type checked when
`skipLibCheck` is enabled. There are legimiate use cases, but typically
they should not exist outside of `node_modules`.

See vitejs/vite#19693
Copy link
vercel bot commented Mar 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 28, 2025 9:48am
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 28, 2025 9:48am
next-intl-example-app-router-without-i18n-routing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 28, 2025 9:48am

Copy link
vercel bot commented Mar 27, 2025

@remcohaszing is attempting to deploy a commit to the next-intl Team on Vercel.

A member of the Team first needs to authorize it.

@amannn
Copy link
Owner
amannn commented Mar 27, 2025

Hmm, example-app-router in this repo uses skipLibCheck and using global.d.ts works just fine in this app:

Do you have some more background or a reproduction where global.d.ts is ignored due to usage of skipLibCheck?

@remcohaszing
Copy link
Contributor Author

I decided to do a little write-up / playground to link to: https://github.com/remcohaszing/skiplibcheck


I just started using next-intl by the way and I’m loving it! ❤️

@amannn
Copy link
Owner
amannn commented Mar 27, 2025

I decided to do a little write-up / playground to link to: https://github.com/remcohaszing/skiplibcheck

That's interesting, thanks for writing this down!

So if I understand correctly, with skipLibCheck, there's no type checking within global.d.ts, but the types from this file will be used fine across an application. I have to admit, I ran into errors myself in this file, e.g. providing an invalid path for messages and the error being swallowed silently with me being left confused as to why it's not working.

That's also the reason why in the troubleshooting section for type augmentation, there's an entry for:

You’re using correct paths for all modules you’re importing into your global declaration file.

I think if we get rid of the .d in the filename, we could get rid of that.

I mostly went with global.d.ts since it seems to be a known pattern across the ecosystem to use a declaration file for type-only files (like vite-env.d.ts, next-env.d.ts). That being said, I think I agree with your reasoning here.

I need to leave for today but will have another look at this tomorrow, I'll be in touch!

I just started using next-intl by the way and I’m loving it! ❤️

That's awesome to hear! Definitely let me know if you have some feedback, I'm always really happy to hear from curious developers! 🤓

@remcohaszing
Copy link
Contributor Author

You’re using correct paths for all modules you’re importing into your global declaration file.

I think if we get rid of the .d in the filename, we could get rid of that.

I agree! What should we call it? The types file? Augmentation file?

I mostly went with global.d.ts since it seems to be a known pattern across the ecosystem to use a declaration file for type-only files (like vite-env.d.ts, next-env.d.ts). That being said, I think I agree with your reasoning here.

I understand. I don’t know who started this pattern, but it’s wide-spread. I’m trying to unnormalize it. It’s a pure coincidence I saw this while implementing next-intl.

I just started using next-intl by the way and I’m loving it! ❤️

That's awesome to hear! Definitely let me know if you have some feedback, I'm always really happy to hear from curious developers! 🤓

I love that you mention a solution for markdown/MDX! Also the way you use type augmentations. One thing I do miss coming from react-intl is a way to synchronize message keys between the code and translations, especially to purge unused messages.

Copy link
Owner
@amannn amannn left a comment

Choose a reason for hiding this comment

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

I just had another look, and I think this is a good idea—many thanks for proposing it! 🙌


I agree! What should we call it? The types file? Augmentation file?

I just had a look through the docs and I think we don't have to give it a particular name—at least as far as the docs are concerned.

@@ -289,7 +289,7 @@ export const formats = {

Now, you can include the `formats` in your `AppConfig`:

```ts filename="global.d.ts"
```ts filename="global.ts"
Copy link
Owner

Choose a reason for hiding this comment

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

Further below, could you remove this bullet?

You’re using correct paths for all modules you’re importing into your global declaration file.

(this should no longer be necessary thanks to your proposed change)

@amannn
Copy link
Owner
amannn commented Mar 28, 2025

One thing I do miss coming from react-intl is a way to synchronize message keys between the code and translations, especially to purge unused messages.

Are you referring to message extraction here?


Somewhat off-topic, I'm always really curious about what kind of strategy experienced developers like to use for structuring their messages. Do you have an opinion on this?

Now that module augmentations are type checked, TypeScript will show an
error for invalid module names.
Copy link
Owner
@amannn amannn left a comment

Choose a reason for hiding this comment

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

Awesome, thanks a lot @remcohaszing! 🙌

@amannn amannn changed the title docs: fix type checking for augmentations docs: Suggest to use global.ts instead of global.d.ts for better compatibility with skipLibCheck Mar 28, 2025
@amannn amannn merged commit 900e834 into amannn:main Mar 28, 2025
5 of 6 checks passed
@remcohaszing remcohaszing deleted the no-declaration-files branch March 28, 2025 10:53
5FEC
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.

2 participants
0