{"id":11320,"library":"micromark-util-types","title":"micromark Utility Types","description":"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.","status":"active","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/micromark/micromark#main","tags":["javascript","micromark","util","utility","typescript","types"],"install":[{"cmd":"npm install micromark-util-types","lang":"bash","label":"npm"},{"cmd":"yarn add micromark-util-types","lang":"bash","label":"yarn"},{"cmd":"pnpm add micromark-util-types","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package exports only TypeScript types; `import type` is essential. Attempting to import values will result in a runtime error or compilation failure.","wrong":"import { Point } from 'micromark-util-types'","symbol":"Point","correct":"import type { Point } from 'micromark-util-types'"},{"note":"As an ESM-only package focused on types, CommonJS `require()` is not supported for importing these declarations.","wrong":"const { State } = require('micromark-util-types')","symbol":"State","correct":"import type { State } from 'micromark-util-types'"},{"note":"There are no default exports. All types are named exports and must be imported explicitly using `import type { ... } from '...'`.","wrong":"import TokenType from 'micromark-util-types'","symbol":"TokenType","correct":"import type { TokenType } from 'micromark-util-types'"}],"quickstart":{"code":"import type {\n  Code,\n  State,\n  Effects,\n  TokenType,\n  Point,\n  Token\n} from 'micromark-util-types';\n\n// Example: A simple state function for a custom micromark extension\nfunction factory(effects: Effects, ok: State, nok: State): State {\n  return start;\n\n  function start(code: Code): State | undefined {\n    // Implement custom parsing logic here\n    if (code === 91 /* `[` */) {\n      effects.enter('myCustomNode' as TokenType);\n      effects.consume(code);\n      return afterOpenBracket;\n    }\n    return nok(code);\n  }\n\n  function afterOpenBracket(code: Code): State | undefined {\n    if (code === 93 /* `]` */) {\n      effects.exit('myCustomNode' as TokenType);\n      effects.consume(code);\n      return ok;\n    }\n    return nok(code);\n  }\n}\n\n// This code snippet demonstrates how to leverage types from micromark-util-types\n// within a custom micromark extension. The 'factory' function would be integrated\n// into a micromark tokenizer. This file compiles but does not have a runtime effect\n// as it's purely for type demonstration.\nconsole.log('Micromark types loaded for extension development.');\n","lang":"typescript","description":"Demonstrates importing and utilizing key TypeScript types like `Code`, `State`, `Effects`, `TokenType`, `Point`, and `Token` to define functions for a custom micromark tokenizer extension."},"warnings":[{"fix":"Consult the `micromark` monorepo changelog or relevant package `README` for version compatibility. Upgrade `micromark-util-types` to a major version explicitly supporting your `micromark` core version, if available.","message":"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.","severity":"breaking","affected_versions":">=2.0.0 (when used with micromark@4.0.0+)"},{"fix":"Always use `import type { SymbolName } from 'micromark-util-types'` to correctly import type definitions.","message":"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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your Node.js environment meets the minimum requirement (currently Node.js 16+ for `micromark-util-types@2`). Upgrade Node.js if necessary.","message":"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.","severity":"breaking","affected_versions":"<2.0.0 (or newer majors with older Node.js)"},{"fix":"Use `import type` statements within an ESM context or a build setup that transpiles to ESM. If stuck in CommonJS, consider dynamic `import()` or review your project's module strategy.","message":"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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statement to `import type { someValue } from 'micromark-util-types'`.","cause":"Attempting to import a non-type value or a type without the `type` keyword from `micromark-util-types`, which only exports TypeScript types.","error":"Module 'micromark-util-types' has no exported member 'someValue'. Did you mean to use 'import type'?"},{"fix":"Ensure 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.","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`).","error":"Cannot find module 'micromark-util-types' or its corresponding type declarations."},{"fix":"Review 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.","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.","error":"TypeError: micromark_util_types_1.Point is not a constructor"}],"ecosystem":"npm"}