Skip to content

tsc CLI: option to always exit with 0 exit code #13280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
OliverJAsh opened this issue Jan 4, 2017 · 11 comments
Open

tsc CLI: option to always exit with 0 exit code #13280

OliverJAsh opened this issue Jan 4, 2017 · 11 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@OliverJAsh
Copy link
Contributor

It would be nice if the tsc command had an option to always exit with a 0 exit code when there were compile errors. I want to run something in my script after compiling. Currently I have to do this:

set -e
# script stuff
set +e
tsc …
set -e

However this workaround means all errors from tsc will be silently ignored, not just compile errors.

@mhegazy mhegazy added the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label Jan 4, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Jan 4, 2017

Not sure if there is enough utility for adding a new flag. waiting for other user scenarios.

@gcnew
Copy link
Contributor

gcnew commented Jan 5, 2017

Could you elaborate on which errors are compile errors and which are not? I think shell scripting can help here, but I don't know what exactly you are after.

@OliverJAsh
Copy link
Contributor Author

To clarify, I want to run tsc to transpile regardless of compile errors. If there are other errors, however (e.g. incorrect flag provided to tsc), I still want it to error.

@RyanCavanaugh RyanCavanaugh added the Suggestion An idea for TypeScript label Aug 7, 2017
@BrandiATMuhkuh
Copy link

BrandiATMuhkuh commented Apr 24, 2018

currently I solve the issue with tsc || exit 0

@QingLeiLi
Copy link

For me, It is not a really solution, typescript should support it natively as there are some case we can not control the cli exec, eg: storybook.

@shamilovtim
Copy link

bump. this caused major issues in a popular and highly connected library

@FMGordillo
Copy link

FMGordillo commented Dec 14, 2020

Tried to use pre-commit hooks and this scenario arised:

#!/bin/sh

RED="\033[1;31m"
GREEN="\033[1;32m"
NC="\033[0m"

linter_exit_code=1
tsc_exit_code=1
staged_js_files=$(git diff --cached --diff-filter=d --name-only | grep .ts$)

./node_modules/.bin/eslint $staged_js_files --quiet --fix
linter_exit_code=$?

./node_modules/.bin/tsc
tsc_exit_code=$?

git add -f $staged_js_files

if [ $linter_exit_code -ne 0 ]
  then
    echo "${RED} ❌ ESLint${NC}"
  else
    echo "${GREEN} ✔ ESLint${NC}"
fi

if [ $tsc_exit_code -ne 0 ]
  then
    echo "${RED} ❌ Typescript${NC}"
  else
    echo "${GREEN} ✔ Typescript${NC}"
fi

if [ $linter_exit_code != 0 && $tsc_exit_code != 0 ]
  then
    exit 1
  else
  echo "... Why?"
    exit 0
fi

@mnpenner
Copy link

mnpenner commented Mar 14, 2021

I'm running tsc like this for now:

#!/usr/bin/env bash
set -veufo pipefail

pnpx tsc -p . || echo "WARNING: tsc exited with status code $?"

The || echo prevents the script from aborting (because echo will succeed) and also tells you the status code (just in case you missed the spew of errors).

Alternatively, you can use || true if you really don't care.


Bonus tip:

You can check if it actually hard failed (didn't compile vs complaining about types) by checking if some file exists. These are the last 2 lines of my script:

cd dist
test -f "$(jq -r .bin package.json)"

That will confirm:

  1. I copied my package.json into my dist/ dir like I want
  2. The "bin" option is set (I'm making a CLI app, change to "main" if you're making a lib)
  3. It points to a real file

@MartinMuzatko
Copy link

I'm building a TS monorepo. Adding || true to each package, while I could control that globally via the tsconfig I already extend from in every package would be great.

@mohitatray
Copy link

mohitatray commented May 11, 2022

If noEmitOnError is set to false, then tsc should exit with exit code 0 when code is emitted even if there were errors. This is the expected behaviour. I am migrating my JS files to TS and there are some errors which I will fix later. But now this deploy script only runs tsc and not the deploy because tsc exits with error code -
tsc && ./deploy.sh
tsc should exit with exit code 0 when it emits code.

@ProdigySim
Copy link

Here's my use case for this feature:

I have a project that is gradually adopting TS and does not have 100% strict compliance yet. So, almost every time we run tsc we expect some errors.

However, sometimes code gets checked in that breaks tsc completely (Call Stack size exceeded, OOM, etc.). I would like to build a CICD job that will ensure that tsc --noEmit will run without encountering a Fatal Error. This is difficult to do if TSC always exits with an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests