Skip to content

Instantly share code, notes, and snippets.

@sushichan044
Last active June 30, 2025 14:13
Show Gist options
  • Select an option

  • Save sushichan044/1ca2bf04cd65cdda167ca427f127cef0 to your computer and use it in GitHub Desktop.

Select an option

Save sushichan044/1ca2bf04cd65cdda167ca427f127cef0 to your computer and use it in GitHub Desktop.
shorthand alias to execute your typescript with nodejs
#!/bin/sh
# execute typescript with node.js
nts() {
if ! type "node" >/dev/null 2>&1; then
echo "node is not installed"
return 1
fi
if ! type "npx" >/dev/null 2>&1; then
echo "npx is not available"
return 1
fi
if [ -z "$1" ]; then
echo "Usage: nts <file.ts>"
return 1
fi
if npx -y semver@latest -r ">=23.6.0 <24 || >=24.3.0" "$(node -v)"; then
node --experimental-transform-types "$1"
elif npx -y semver@latest -r ">=22.7.0 <23.6.0" "$(node -v)"; then
node --experimental-transform-types --experimental-strip-types "$1"
else
echo "Node.js version does not support typescript execution."
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment