Skip to content

Commit e0bbe6f

Browse files
authored
Merge pull request #195 from ajafff/patch-1
Use ImportType for type-only imports
2 parents 6984f92 + b7b5f73 commit e0bbe6f

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

Writing-a-Language-Service-Plugin.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ Let's write a simple plugin. Our plugin will remove a user-configurable list of
2525

2626
### Setup and Initialization
2727

28-
When your plugin is loaded, it's first initialized as a factory function with its first parameter set to `{typescript: ts}`. It's important to use *this* value, rather than the imported `ts` module, because any version of TypeScript might be loaded by tsserver. If you use any other object, you'll run into compatibility problems later because enum values may change between versions. Note below that ts_module is imported *only* for the type annotation.
28+
When your plugin is loaded, it's first initialized as a factory function with its first parameter set to `{typescript: ts}`. It's important to use *this* value, rather than the imported `ts` module, because any version of TypeScript might be loaded by tsserver. If you use any other object, you'll run into compatibility problems later because enum values may change between versions.
2929

3030
Here's the minimal code that handles this injected `ts` value:
3131
```ts
32-
import * as ts_module from "typescript/lib/tsserverlibrary";
33-
34-
function init(modules: { typescript: typeof ts_module }) {
32+
function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) {
3533
const ts = modules.typescript;
3634
/* More to come here */
3735
}
@@ -45,7 +43,7 @@ TypeScript Language Service Plugins use the [Decorator Pattern](https://en.wikip
4543

4644
Let's fill in some more code to properly set up a decorator:
4745
```ts
48-
function init(modules: { typescript: typeof ts_module }) {
46+
function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) {
4947
const ts = modules.typescript;
5048

5149
function create(info: ts.server.PluginCreateInfo) {
@@ -160,9 +158,7 @@ function create(info: ts.server.PluginCreateInfo) {
160158
## Putting it all together
161159

162160
```ts
163-
import * as ts_module from "../node_modules/typescript/lib/tsserverlibrary";
164-
165-
function init(modules: { typescript: typeof ts_module }) {
161+
function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) {
166162
const ts = modules.typescript;
167163

168164
function create(info: ts.server.PluginCreateInfo) {

0 commit comments

Comments
 (0)