micromark Utility Types
micromark-util-types is a utility package within the micromark ecosystem, currently at version 2.0.2. Its sole purpose is to provide a comprehensive set of TypeScript types that are shared across various micromark packages, enabling developers to create robust and type-safe micromark extensions. The package itself exports no runtime code or identifiers, serving purely as a type declaration module. This focused approach differentiates it from general-purpose utility libraries, making it an essential dependency for anyone building custom parsers or extensions with TypeScript for micromark. Releases typically align with the broader micromark monorepo, with updates often focusing on performance, bug fixes, and maintaining compatibility with supported Node.js versions and the latest micromark parser core.
Common errors
-
Module 'micromark-util-types' has no exported member 'someValue'. Did you mean to use 'import type'?
cause Attempting to import a non-type value or a type without the `type` keyword from `micromark-util-types`, which only exports TypeScript types.fixChange your import statement to `import type { someValue } from 'micromark-util-types'`. -
Cannot find module 'micromark-util-types' or its corresponding type declarations.
cause The package is not installed, or TypeScript is misconfigured and cannot locate the type declarations (e.g., `moduleResolution` settings, incorrect `baseUrl`, or an outdated `tsconfig.json`).fixEnsure the package is installed: `npm install micromark-util-types`. Verify your `tsconfig.json` has appropriate `moduleResolution` (e.g., `node16` or `bundler`) and `typeRoots` settings. For older TypeScript versions, ensure compatibility with micromark's types. -
TypeError: micromark_util_types_1.Point is not a constructor
cause This error occurs at runtime when a symbol imported from `micromark-util-types` is treated as a JavaScript value (e.g., a class or function) rather than a TypeScript type. This package provides no runtime code.fixReview the code where `Point` (or other types from this package) is used. It should only appear in type annotations or declarations, never as a value in runnable JavaScript code. Ensure `import type` is used.
Warnings
- breaking The `micromark-util-types@2` package is explicitly stated to be compatible with `micromark@3` and Node.js 16+. While the overall micromark monorepo is at version `4.x`, using `micromark-util-types@2` with `micromark@4` (or newer) might lead to type mismatches or runtime issues if API types have diverged. Always check for corresponding major versions of utility packages when updating the main `micromark` parser.
- gotcha This package exports *only* TypeScript types and no runtime JavaScript code. Attempting to import any symbol without the `type` keyword (e.g., `import { Point } from '...'`) will lead to compilation errors in TypeScript or runtime errors if type-checking is bypassed, as there are no actual values to import.
- breaking As part of the unified collective, `micromark-util-types` adheres to Node.js LTS version compatibility. Major releases of micromark packages often drop support for unmaintained Node.js versions. `micromark-util-types@2` specifically targets Node.js 16+. Using it with older Node.js environments is not supported and may lead to unexpected behavior or crashes.
- gotcha The package is ESM-only. Direct `require()` statements in CommonJS modules will fail at runtime. Even with transpilation, the expectation is for `import` statements and an ESM context for proper operation.
Install
-
npm install micromark-util-types -
yarn add micromark-util-types -
pnpm add micromark-util-types
Imports
- Point
import { Point } from 'micromark-util-types'import type { Point } from 'micromark-util-types' - State
const { State } = require('micromark-util-types')import type { State } from 'micromark-util-types' - TokenType
import TokenType from 'micromark-util-types'
import type { TokenType } from 'micromark-util-types'
Quickstart
import type {
Code,
State,
Effects,
TokenType,
Point,
Token
} from 'micromark-util-types';
// Example: A simple state function for a custom micromark extension
function factory(effects: Effects, ok: State, nok: State): State {
return start;
function start(code: Code): State | undefined {
// Implement custom parsing logic here
if (code === 91 /* `[` */) {
effects.enter('myCustomNode' as TokenType);
effects.consume(code);
return afterOpenBracket;
}
return nok(code);
}
function afterOpenBracket(code: Code): State | undefined {
if (code === 93 /* `]` */) {
effects.exit('myCustomNode' as TokenType);
effects.consume(code);
return ok;
}
return nok(code);
}
}
// This code snippet demonstrates how to leverage types from micromark-util-types
// within a custom micromark extension. The 'factory' function would be integrated
// into a micromark tokenizer. This file compiles but does not have a runtime effect
// as it's purely for type demonstration.
console.log('Micromark types loaded for extension development.');