Tscm
TypeScript Compiler Macros - experimental function-like macros for TypeScript with IDE & type-checking support (deprecated)
Install / Use
/learn @johanholmerin/TscmREADME
Deprecated
Since TypeScript 5 this project is no longer supported
tscm
Function-like macros for TypeScript, inspired by Rust
- Fully type-checked
- IDE support - correct messages, types and diagnostics while editing
- easy to use, easy to write
- Generates correct source-maps
- Compatible Babel plugin
For a collection of example macros, like GraphQL or SQL, see the tscm-examples repository.
Installation
Bring your own TypeScript, version 4.0 or higher
# Yarn
yarn add -D tscm typescript
# npm
npm install -D tscm typescript
Example
Usage
// macros are imported like normal
import { macro } from './macros';
// Two non-null-assertion operators are used as indicator for macro calls
const val = macro!!('literal', identifier);
Macro definition
Macros are normal functions that get the CallExpression Node as parameter and return a new Node. They can be local files or npm packages. For more information see the Writing macros guide.
const t = require('@babel/types');
/**
* @type {import('tscm/macro').Macro}
*/
module.exports.macro = function ({ node }) {
// Returns that arguments as an array
return t.arrayExpression(node.arguments);
};
Compiling
To compile, use tscm instead of tsc. If you are using a bundler, see Bundler setup.
npx tscm
Editor config
To get the correct types in your editor, make sure to point it to tscm.
coc.nvim
// .vim/coc-settings.json
{
"tsserver.ignoreLocalTsserver": true,
"tsserver.tsdk": "./node_modules/tscm/typescript/lib"
}
VS Code
Make sure to select Use Workspace Version under TypeScript: Select TypeScript version
// .vscode/settings.json
{
"typescript.tsdk": "./node_modules/tscm/typescript/lib"
}
Documentation
Related Skills
Writing Hookify Rules
90.0kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
99.7kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
openhue
343.1kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
343.1kElevenLabs text-to-speech with mac-style say UX.
