{"id":25805,"library":"jsii-sampiler","title":"jsii-sampiler","description":"jsii-sampiler is a utility for transcribing TypeScript code snippets into other jsii-supported languages (Java, C#, Python, Go, etc.). It is part of the AWS jsii ecosystem and works in tandem with jsii-pacmak for documentation generation. The latest stable version (v1.x) is actively maintained with frequent bug fix releases. It uses grammatical and type-aware translation for compiling or non-compiling samples and supports void masking to hide boilerplate. Its key differentiator is deep integration with the jsii type system, enabling accurate multi-language translations beyond simple text transformation.","status":"active","version":"0.20.6","language":"javascript","source_language":"en","source_url":"https://github.com/aws/jsii","tags":["javascript"],"install":[{"cmd":"npm install jsii-sampiler","lang":"bash","label":"npm"},{"cmd":"yarn add jsii-sampiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsii-sampiler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v1.x; CommonJS require not supported.","wrong":"const { sampile } = require('jsii-sampiler')","symbol":"sampile","correct":"import { sampile } from 'jsii-sampiler'"},{"note":"Sampiler is a named export, not default.","wrong":"import Sampiler from 'jsii-sampiler'","symbol":"Sampiler","correct":"import { Sampiler } from 'jsii-sampiler'"},{"note":"TypeScript type import; use 'import type' if only used as a type.","wrong":"","symbol":"TypeScriptSnippet","correct":"import { TypeScriptSnippet } from 'jsii-sampiler'"}],"quickstart":{"code":"import { sampile } from 'jsii-sampiler';\n\n// TypeScript code snippet to translate\nconst tsCode = `\n  const greeting: string = 'Hello';\n  console.log(greeting);\n`;\n\n// Translate to Python\nconst pythonCode = sampile(tsCode, 'python');\nconsole.log(pythonCode);\n// Output: greeting = 'Hello'\n// print(greeting)\n","lang":"typescript","description":"Basic usage: translate a TypeScript snippet to Python using the sampile function."},"warnings":[{"fix":"Upgrade Node to >=10.3.0 (but ideally use current LTS).","message":"Version 1.x dropped support for Node 10; require Node >= 10.3.0.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure void expressions are used only where valid JavaScript/TypeScript syntax allows.","message":"void masking directives are removed in output but affect translation; incorrect placement may produce invalid code.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Provide compilable samples with full type annotations for best results.","message":"Non-compiling samples lose type information; struct fields, nested types, and dictionary vs struct disambiguation may be incorrect.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Replace Sample.sampile() with import { sampile } from 'jsii-sampiler'.","message":"The 'Sample' class from earlier versions is deprecated; use 'sampile' function directly.","severity":"deprecated","affected_versions":">=0.15.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Move void directives to statement or comma expression positions where void is syntactically valid.","cause":"Using void masking outside of allowed contexts (e.g., expression positions).","error":"SyntaxError: Unexpected token 'void'"},{"fix":"npm install jsii-sampiler and use import { sampile } from 'jsii-sampiler' (ESM).","cause":"Missing installation or incorrect import path.","error":"Cannot find module 'jsii-sampiler' or its corresponding type declarations."},{"fix":"Use import { sampile } from 'jsii-sampiler', not import sampile from 'jsii-sampiler'.","cause":"Improper import (e.g., default import instead of named).","error":"TypeError: sampile is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}