Skip to content
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

Update TypeScript.md #4126

Merged
merged 6 commits into from Jul 11, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/Reference/TypeScript.md
Expand Up @@ -661,6 +661,30 @@ However, there are a couple of suggestions to help improve this experience:
[npm-check](https://www.npmjs.com/package/npm-check) to verify plugin
dependencies are being used somewhere in your project.

Note that using `require` won't load the type definitions properly and may
mikicho marked this conversation as resolved.
Show resolved Hide resolved
cause type errors.
TypeScript can only identify the types that are directly imported into code
which means that you can use require inline with import on top, for example:
mikicho marked this conversation as resolved.
Show resolved Hide resolved

```typescript
import 'plugin' // here will trigger the type augmentation.

fastify.register(require('plugin'))
```

```typescript
import plugin from 'plugin' // here will trigger the type augmentation.

fastify.register(plugin)
```

Or even explicit config on tsconfig
```json
mikicho marked this conversation as resolved.
Show resolved Hide resolved
{
"types": ["plugin"] // we force TypeScript to import the types
}
```

## Code Completion In Vanilla JavaScript

Vanilla JavaScript can use the published types to provide code completion (e.g.
Expand Down