Comprehensive TypeScript type definitions for the SWC JavaScript/TypeScript transformation and minification APIs.
npx @tessl/cli install tessl/npm-swc--types@0.1.0@swc/types provides comprehensive TypeScript type definitions for @swc/core APIs, serving as a lightweight dependency for tools that need SWC type information without depending on the full @swc/core package. It contains extensive type definitions for JavaScript minification options (including Terser-compatible interfaces), parsing configurations, AST node types, plugin interfaces, and compilation assumptions.
npm install @swc/typesimport type {
Options, Config, JscConfig, ModuleConfig,
Plugin, ParseOptions, JsMinifyOptions,
// AST types
Program, Module, Statement, Expression,
// JSX types
JSXElement, JSXFragment, JSXElementChild,
// TypeScript types
TsType, TsInterfaceDeclaration,
// Babel assumptions
Assumptions
} from "@swc/types";CommonJS:
const { Options, Config } = require("@swc/types");import type { Options, JscConfig, ModuleConfig } from "@swc/types";
// SWC compilation configuration with JSX support
const swcOptions: Options = {
jsc: {
target: "es2020",
parser: {
syntax: "typescript",
tsx: true,
decorators: true
},
transform: {
react: {
runtime: "automatic"
}
},
assumptions: {
constantSuper: true,
noClassCalls: true,
privateFieldsAsProperties: true
}
},
module: {
type: "es6"
},
minify: true
};
// Minification configuration
const minifyOptions: JsMinifyOptions = {
compress: {
dead_code: true,
drop_console: true
},
mangle: {
topLevel: true
}
};@swc/types is organized around several key type categories:
Core configuration interfaces for SWC compilation, parsing, and transformation. Essential for any tool integrating with SWC.
interface Options extends Config {
script?: boolean;
cwd?: string;
filename?: string;
root?: string;
rootMode?: "root" | "upward" | "upward-optional";
}
interface Config {
test?: string | string[];
exclude?: string | string[];
env?: EnvConfig;
jsc?: JscConfig;
module?: ModuleConfig;
minify?: boolean;
sourceMaps?: boolean | "inline";
}
interface JscConfig {
assumptions?: Assumptions;
parser?: ParserConfig;
transform?: TransformConfig;
target?: JscTarget;
minify?: JsMinifyOptions;
}Complete abstract syntax tree type definitions covering all JavaScript and TypeScript syntax elements. Used for AST manipulation and analysis.
type Program = Module | Script;
interface Module extends Node, HasSpan {
type: "Module";
body: ModuleItem[];
}
type Statement =
| BlockStatement | EmptyStatement | DebuggerStatement
| WithStatement | ReturnStatement | LabeledStatement
| BreakStatement | ContinueStatement | IfStatement
| SwitchStatement | ThrowStatement | TryStatement
| WhileStatement | DoWhileStatement | ForStatement
| ForInStatement | ForOfStatement | Declaration
| ExpressionStatement;
type Expression =
| ThisExpression | ArrayExpression | ObjectExpression
| FunctionExpression | UnaryExpression | UpdateExpression
| BinaryExpression | AssignmentExpression | MemberExpression
| ConditionalExpression | CallExpression | NewExpression
| Identifier | Literal | TemplateLiteral
| ArrowFunctionExpression | ClassExpression | YieldExpression
| AwaitExpression | OptionalChainingExpression;TypeScript-specific AST nodes and type system representations for TypeScript compilation and analysis.
type TsType =
| TsKeywordType | TsThisType | TsFnOrConstructorType
| TsTypeReference | TsTypeQuery | TsTypeLiteral
| TsArrayType | TsTupleType | TsOptionalType
| TsRestType | TsUnionOrIntersectionType
| TsConditionalType | TsInferType | TsParenthesizedType
| TsTypeOperator | TsIndexedAccessType | TsMappedType
| TsLiteralType | TsTypePredicate | TsImportType;
interface TsInterfaceDeclaration extends Node, HasSpan {
type: "TsInterfaceDeclaration";
id: Identifier;
declare: boolean;
typeParams?: TsTypeParameterDeclaration;
extends: TsExpressionWithTypeArguments[];
body: TsInterfaceBody;
}
interface TsTypeAliasDeclaration extends Node, HasSpan {
type: "TsTypeAliasDeclaration";
declare: boolean;
id: Identifier;
typeParams?: TsTypeParameterDeclaration;
typeAnnotation: TsType;
}Terser-compatible interfaces for JavaScript minification and code optimization.
interface JsMinifyOptions {
compress?: TerserCompressOptions | boolean;
format?: JsFormatOptions;
mangle?: TerserMangleOptions | boolean;
ecma?: TerserEcmaVersion;
keep_classnames?: boolean;
keep_fnames?: boolean;
module?: boolean | "unknown";
sourceMap?: boolean;
}
interface TerserCompressOptions {
arguments?: boolean;
arrows?: boolean;
booleans?: boolean;
dead_code?: boolean;
drop_console?: boolean;
drop_debugger?: boolean;
evaluate?: boolean;
// ... extensive compression options
}Type definitions for various JavaScript module systems and their configuration options.
type ModuleConfig =
| Es6Config | CommonJsConfig | UmdConfig
| AmdConfig | NodeNextConfig | SystemjsConfig;
interface BaseModuleConfig {
strict?: boolean;
strictMode?: boolean;
lazy?: boolean | string[];
importInterop?: "swc" | "babel" | "node" | "none";
}
interface Es6Config extends BaseModuleConfig {
type: "es6";
}
interface CommonJsConfig extends BaseModuleConfig {
type: "commonjs";
}Parser configuration for JavaScript and TypeScript syntax support.
type ParseOptions = ParserConfig & {
comments?: boolean;
script?: boolean;
target?: JscTarget;
};
type ParserConfig = TsParserConfig | EsParserConfig;
interface TsParserConfig {
syntax: "typescript";
tsx?: boolean;
decorators?: boolean;
}
interface EsParserConfig {
syntax: "ecmascript";
jsx?: boolean;
decorators?: boolean;
// ... additional ES feature flags
}Complete JSX/React AST node definitions for parsing and transforming JSX syntax. Essential for React applications and JSX-based frameworks.
interface JSXElement extends Node, HasSpan {
type: "JSXElement";
opening: JSXOpeningElement;
children: JSXElementChild[];
closing?: JSXClosingElement;
}
interface JSXFragment extends Node, HasSpan {
type: "JSXFragment";
opening: JSXOpeningFragment;
children: JSXElementChild[];
closing: JSXClosingFragment;
}
type JSXElementName =
| Identifier // <Button>
| JSXMemberExpression // <UI.Button>
| JSXNamespacedName; // <svg:circle>
type JSXElementChild =
| JSXText | JSXExpressionContainer
| JSXSpreadChild | JSXElement | JSXFragment;Optimization assumptions for Babel compatibility, enabling more efficient transformations when code behavior is predictable.
interface Assumptions {
/** Assume array-like objects are iterable */
arrayLikeIsIterable?: boolean;
/** Assume re-exported bindings are constant */
constantReexports?: boolean;
/** Assume super class doesn't change at runtime */
constantSuper?: boolean;
/** Assume classes are never called as functions */
noClassCalls?: boolean;
/** Transform private fields as regular properties */
privateFieldsAsProperties?: boolean;
/** Assume getters have no side effects */
pureGetters?: boolean;
// ... 17+ additional optimization flags
}interface Node {
type: string;
}
interface HasSpan {
span: Span;
}
interface Span {
start: number;
end: number;
ctxt: number;
}
type JscTarget =
| "es3" | "es5" | "es2015" | "es2016" | "es2017"
| "es2018" | "es2019" | "es2020" | "es2021"
| "es2022" | "es2023" | "es2024" | "esnext";
type TerserEcmaVersion = 5 | 2015 | 2016 | string | number;
interface Output {
code: string;
map?: string;
}