ts-transform-args
v0.1.2
Published
TypeScript transformer that eliminates option object allocations by converting them into positional arguments at compile time. Readable code, zero GC overhead
Maintainers
Readme
ts-transform-args
TypeScript compiler transformer that rewrites option objects into positional arguments at compile time. Eliminates short-lived allocations on hot paths while keeping source code readable.
// source
createParticle({ x: pos.x, y: pos.y, vx: 0.1, vy: -0.3, ttl: 60 });
// emitted JS
createParticle(pos.x, pos.y, 0.1, -0.3, 60);Function bodies are rewritten too (opts.x becomes x), so the option object is fully eliminated.
Setup
npm install ts-transform-args typescript ts-patch
npx ts-patch installtsconfig.json:
{
"compilerOptions": {
"types": ["ts-transform-args"],
"plugins": [{ "transform": "ts-transform-args" }]
}
}Adding "ts-transform-args" to types makes the CallArgs interface available globally without imports. If you use other type packages (e.g. @types/node), include them too since an explicit types array overrides automatic @types resolution.
Usage
Define an interface extending CallArgs. Property declaration order determines argument position.
interface Opts extends CallArgs {
name: string;
age: number;
active: boolean;
}
declare function createUser(opts: Opts): void;
createUser({ active: true, name: "alice", age: 30 });
// emits: createUser("alice", 30, true)Multiple CallArgs parameters, plain parameters mixed with CallArgs, constructors, and methods are all supported.
Programmatic API
import { transformSource } from 'ts-transform-args/compile';
const js = transformSource(`
interface Opts extends CallArgs { x: number; y: number; }
declare function move(opts: Opts): void;
move({ x: 10, y: 20 });
`);
// js => 'move(10, 20);'License
MIT
