Skip to content

Commit

Permalink
Update TypeScript.md (#4126)
Browse files Browse the repository at this point in the history
* Update TypeScript.md

* Update TypeScript.md

* Update TypeScript.md

* Update docs/Reference/TypeScript.md

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

* Update docs/Reference/TypeScript.md

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

* Update docs/Reference/TypeScript.md

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>
  • Loading branch information
mikicho and Fdawgs committed Jul 11, 2022
1 parent cf091f7 commit d45bcb6
Showing 1 changed file with 24 additions and 0 deletions.
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` will not load the type definitions properly and may
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:

```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
```jsonc
{
"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

0 comments on commit d45bcb6

Please sign in to comment.