Skip to content

Installing

FeatureSupported Status
JSDocs and Type Hover boxes
Error Handling/Messages
Type Extraction
Code Completions
Code Highlighting
Code Cutting
Callouts
TS Compiler Overrides
Show Emitted Files⛔️

Install the package with your favorite package manager

Terminal window
npm i expressive-code-twoslash

Add ecTwoSlash to your Expressive Code plugin list

import {
function defineConfig<const TLocales extends Locales = never, const TDriver extends SessionDriverName = never, const TFontProviders extends Array<FontProvider> = never>(config: AstroUserConfig<TLocales, TDriver, TFontProviders>): AstroUserConfig<TLocales, TDriver, TFontProviders>

See the full Astro Configuration API Documentation https://astro.build/config

defineConfig
} from "astro/config";
import
function astroExpressiveCode(integrationOptions?: AstroExpressiveCodeOptions): {
name: string;
hooks: {
"astro:config:setup": (args: unknown) => Promise<void>;
};
}

Astro integration that adds Expressive Code support to code blocks in Markdown & MDX documents.

astroExpressiveCode
from 'astro-expressive-code'
import
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
from "expressive-code-twoslash";
// https://astro.build/config
export default
defineConfig<never, never, never>(config: AstroUserConfig<never, never, never>): AstroUserConfig<never, never, never>

See the full Astro Configuration API Documentation https://astro.build/config

defineConfig
({
AstroUserConfig<TLocales extends Locales = never, TSession extends SessionDriverName = never, TFontProviders extends Array<FontProvider> = never>.integrations?: (false | AstroIntegration | (false | AstroIntegration | null | undefined)[] | null | undefined)[] | undefined

@docs

@nameintegrations

@typeraw{AstroIntegration[]}

@description

Extend Astro with custom integrations. Integrations are your one-stop-shop for adding framework support (like Solid.js), new features (like sitemaps), and new libraries (like Partytown).

Read our Integrations Guide for help getting started with Astro Integrations.

import react from '@astrojs/react';
import mdx from '@astrojs/mdx';
{
// Example: Add React + MDX support to Astro
integrations: [react(), mdx()]
}

integrations
: [
function astroExpressiveCode(integrationOptions?: AstroExpressiveCodeOptions): {
name: string;
hooks: {
"astro:config:setup": (args: unknown) => Promise<void>;
};
}

Astro integration that adds Expressive Code support to code blocks in Markdown & MDX documents.

astroExpressiveCode
({
plugins?: (ExpressiveCodePlugin | ExpressiveCodePlugin[])[] | undefined

An optional array of plugins that should be used when rendering code blocks.

To add a plugin, import its initialization function and call it inside this array.

If the plugin has any configuration options, you can pass them to the initialization function as an object containing your desired property values.

If any nested arrays are found inside the plugins array, they will be flattened before processing.

plugins
: [
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
()],
}),
],
});

Default config options shown.

function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
({
PluginTwoslashOptions.explicitTrigger?: boolean | RegExp | undefined

If true, requires twoslash to be present in the code block meta for this transformer to be applied.

If a RegExp, requires the RegExp to match a directive in the code block meta for this transformer to be applied.

If false, this transformer will be applied to all code blocks that match the specified languages.

It is recommended to keep this as true to avoid unnecessary processing.

@defaulttrue

explicitTrigger
: true,
PluginTwoslashOptions.languages?: readonly string[] | undefined

The languages to apply this transformer to.

@default["ts", "tsx"]

languages
: ["ts", "tsx", "vue"],
PluginTwoslashOptions.includeJsDoc?: boolean | undefined

If true, includes JSDoc comments in the hover popup.

@defaulttrue

includeJsDoc
: true,
Message: allowNonStandardJsDocTags is required for like this to work
PluginTwoslashOptions.allowNonStandardJsDocTags?: boolean | undefined

Allows non-standard JSDoc tags to be included in the hover popup.

Non-standard tags are tags that are not included in the default JSDoc tag list.

@example @customTag, @docs, @omglookatthis

@defaulttrue

allowNonStandardJsDocTags
: true,
PluginTwoslashOptions.twoslashOptions?: TwoslashOptions | undefined

Options to forward to twoslash.

@default{}

twoslashOptions
: {
TwoslashExecuteOptions.compilerOptions?: ts.CompilerOptions | undefined

Allows setting any of the compiler options from outside the function

compilerOptions
: {
ts.CompilerOptions.moduleResolution?: ts.ModuleResolutionKind | undefined
moduleResolution
: 100 satisfies
(alias) namespace ts
import ts
ts
.
enum ts.ModuleResolutionKind
ModuleResolutionKind
.
function (enum member) ts.ModuleResolutionKind.Bundler = 100
Bundler
,
ts.CompilerOptions.lib?: string[] | undefined
lib
: ["lib.es2022.d.ts", "lib.dom.d.ts", "lib.dom.iterable.d.ts"],
}
},
})