fabiandev / ts-runtime

Runtime Type Checks for TypeScript

Home Page:https://fabiandev.github.io/ts-runtime/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails with compilerOptions.noEmitOnError=true

TruffeCendree opened this issue · comments

Considering simple test.ts file and tsconfig.json like the following:

console.log('it works')
{
  "compilerOptions": {
    "noEmitOnError": true
  }
}

I am able to compile using tsr src/test.ts :

ℹ ts-runtime v0.1.35
✔ Processing (3s)
✔ Scanning (29ms)
✔ Transforming (18ms)
✔ Emitting (82ms)
✔ Done in 2s 819ms.

But not with compilerOptions.noEmitOnError=true using tsr -c tsconfig.json src/test.ts

ℹ ts-runtime v0.1.35
✔ Processing (3s)
✔ Scanning (27ms)
✔ Transforming (18ms)
✖ error TS6053: File '/home/thomas/.nvm/versions/node/v10.0.0/lib/node_modules/ts-runtime/node_modules/typescript/lib/lib.d.ts' not found.
✖ error TS2318: Cannot find global type 'Array'.
✖ error TS2318: Cannot find global type 'Boolean'.
✖ error TS2318: Cannot find global type 'Function'.
✖ error TS2318: Cannot find global type 'IArguments'.
✖ error TS2318: Cannot find global type 'Number'.
✖ error TS2318: Cannot find global type 'Object'.
✖ error TS2318: Cannot find global type 'RegExp'.
✖ error TS2318: Cannot find global type 'String'.
✖ src/test.ts(1,15): error TS2307: Cannot find module 'ts-runtime/lib'.
✖ src/test.ts(2,1): error TS2304: Cannot find name 'console'.
✖ Emitting was interrupted.

lib.d.ts exists at this location (typescript@2.9.2)
If noEmitOnError is set to false, it works again.

Thanks for reporting @veillardt. I did several tests and could experience the same errors. I tried to get around this issue while still using the native option, but it seems I will need to handle noEmitOnError by some custom logic.

However, ts-runtime will abort if there were errors by default, which can be changed with the --force flag. It may be better to remove the force option in favor for noEmitOnError.

Just try to compile the code below with tsr test.ts and tsr --force test.ts

let foo: number = 'bar';