Registry / type-stubs / typescript-template-language-service-decorator

typescript-template-language-service-decorator

JSON →
library2.3.2jsnpmunverified

Framework for decorating a TypeScript language service with support for languages embedded inside template strings. Current stable version is 2.3.2, released July 2021. This library abstracts the complexity of handling template string nodes, allowing developers to focus on the embedded language's content. It is primarily used to build TypeScript language service plugins for tagged template literals (e.g., styled-components, lit-html). Unlike custom language service implementations, this decorator seamlessly integrates with TypeScript's existing infrastructure, handling offset mapping and template context automatically. It ships with TypeScript types and is ESM-and-CJS compatible. Release cadence is low; updates are infrequent and focus on maintenance.

npm install typescript-template-language-service-decorator
INSTALL
IMPORT
SIG · TYPESCRIPT-TEMPLAT
T
typescript-template-language-service-decorator
type-stubsjavascriptv2.3.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

decorateWithTemplateLanguageService
import { decorateWithTemplateLanguageService } from 'typescript-template-language-service-decorator'
const decorateWithTemplateLanguageService = require('typescript-template-language-service-decorator').decorateWithTemplateLanguageService
Named import; also available via default import but named is recommended.
TemplateLanguageService
import type { TemplateLanguageService } from 'typescript-template-language-service-decorator'
import { TemplateLanguageService } from 'typescript-template-language-service-decorator'
This is a type/interface; use `import type` in TypeScript to avoid runtime import.
TemplateContext
import type { TemplateContext } from 'typescript-template-language-service-decorator'
TemplateContext is an interface; use `import type`.

Shows a complete TypeScript server plugin that adds echo completions to template strings tagged with `echo`.

import * as ts from 'typescript/lib/tsserverlibrary'; import { decorateWithTemplateLanguageService, TemplateLanguageService, TemplateContext } from 'typescript-template-language-service-decorator'; class EchoTemplateLanguageService implements TemplateLanguageService { getCompletionsAtPosition( context: TemplateContext, position: ts.LineAndCharacter ): ts.CompletionInfo { const line = context.text.split(/\n/g)[position.line]; return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: [ { name: line.slice(0, position.character), kind: '', kindModifiers: 'echo', sortText: 'echo' } ] }; } } export = (mod: { typescript: typeof ts }) => { return { create(info: ts.server.PluginCreateInfo): ts.LanguageService { return decorateWithTemplateLanguageService( mod.typescript, info.languageService, info.project, new EchoTemplateLanguageService(), { tags: ['echo'] } ); } }; };
Debug
Known issues
gotchaThe library requires 'typescript/lib/tsserverlibrary' as a peer dependency; using 'typescript' alone will fail.
fix
Import from 'typescript/lib/tsserverlibrary' instead of 'typescript'.
affects: >=2.0
breakingIn version 2.3.0, `getDefinitionAndBoundSpan` was added; plugins that override this method may need to update their interface.
fix
Implement the new optional method or update the interface to include it.
affects: =2.3.0
gotchaTemplateContext.text is the raw text of the template string; newlines are preserved and positions are relative to this raw text.
fix
Parse text using `context.text.split(/\n/g)` or similar to get lines.
affects: >=2.0
deprecatedThe old method `getCompletionsAtPosition` used to accept a `string` for relativePosition; now it expects `ts.LineAndCharacter`.
fix
Update to use `ts.LineAndCharacter` object.
affects: <2.0
gotchaIf using CommonJS, you must default-import the module due to ESM/CJS interop.
fix
Use `import pkg from 'typescript-template-language-service-decorator'` with `esModuleInterop` enabled.
affects: >=2.0
Errors
Common errors & fixes
TypeError: Cannot read property 'getLanguageService' of undefined
Using 'typescript' instead of 'typescript/lib/tsserverlibrary'.
fix
Change import to `import * as ts from 'typescript/lib/tsserverlibrary'`.
Module '"typescript-template-language-service-decorator"' has no exported member 'TemplateLanguageService'.
Using non-type import on a type-only export; likely missing 'type' keyword.
fix
Use `import type { TemplateLanguageService } from 'typescript-template-language-service-decorator'`.
error TS2345: Argument of type '{ tags: string[]; }' is not assignable to parameter of type 'TemplateSettings'.
TemplateSettings expects `tags` as `string[]`, but also requires other properties like `enabled`. Provide full object.
fix
Use `{ tags: ['myTag'], enabled: true }`.
Upgrade
Version history
2.3.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
38 hits · last 30 days
node
28
OpenAI (training)
1
Resources
typescript-template-language-service-decorator — npm install typescript-template-language-service-decorator · libregistry