fish-ts
v1.0.1
Published
A small TypeScript-to-fish-shell transpiler.
Maintainers
Readme
fish-ts
What It Is
fish-ts is a small TypeScript-to-fish-shell transpiler.
What It Does
It parses strictly typed TypeScript with the TypeScript compiler API and emits fish script for common shell-like code: variables, functions, calls, strings, numbers, conditionals, loops, arrays, and simple expressions.
Example
TypeScript input:
function greet(who: string, times: number): string {
const message: string = "Hello, " + who;
if (times > 1) {
echo(message);
}
return message;
}
const value: string = command("input");
greet(value, 2);Common fish built-ins are predeclared as TypeScript functions. Use
source("file.fish") for fish's . source shorthand.
Generated fish:
function greet
set -l who $argv[1]
set -l times $argv[2]
set -l message (string join "" 'Hello, ' $who)
if test $times -gt 1
echo $message
end
echo $message
return 0
end
set -g value (command input)
greet $value 2Quickstart
npm install fish-ts
npx fish-ts input.ts > output.fishFor one-off use without adding it to a project:
npx fish-ts input.ts > output.fishYou can also pipe source through stdin:
cat input.ts | npx fish-ts > output.fishUse the API from JavaScript or TypeScript:
import { transpile } from "fish-ts";
console.log(transpile(`const name: string = "world";`));Development
pnpm install
pnpm run build
pnpm testLimitations
- Not a full TypeScript runtime or POSIX shell compiler.
- Best for small, typed, shell-oriented TypeScript.
- Type annotations matter; they drive fish quoting, comparisons, and command emission.
- Only supported syntax lowers to fish; unsupported JavaScript/TypeScript features may emit incomplete or invalid output.
