Ts-node-dev: Compilation errors are unseeable when you use ts-node 8.6.0+.

Created on 23 Jan 2020  Â·  8Comments  Â·  Source: wclr/ts-node-dev

I found that I was unable to see compilation errors when I used ts-node 8.6.0+ like below.

I don't know why, but I seem that I have to use ts-node lower than v8.6.0 if I use ts-node-dev.

Using ts-node version 8.5.4

$ npx ts-node-dev src/boolean.ts
Using ts-node version 8.5.4, typescript version 3.7.5
[ERROR] 23:15:08 ⨯ Unable to compile TypeScript:
src/boolean.ts:7:1 - error TS2322: Type '1' is not assignable to type 'boolean'.

7 isFinished = 1;
  ~~~~~~~~~~

Using ts-node version 8.6.0

$ npx ts-node-dev src/boolean.ts
Using ts-node version 8.6.0, typescript version 3.7.5
{ isFinished: 1 }

src/boolean.ts

let isFinished: boolean = true;
isFinished = 1;
console.log({ isFinished });

Most helpful comment

I found the problem. This commit added backward compatibility with an old (i think), deprecated, flag --type-check https://github.com/TypeStrong/ts-node/commit/8834d645849f5b9a6eb377aaa32e92dc094d40f8. When ts-node-dev initializes its options, if this flag is missing, it becomes false by default, which as a consequence disables type checking. If you add the --type-check flag, then type checking is working.
As a fix i think we should remove this option completely, we can also make it true by default, but since it's deprecated...
@whitecolor what do you suggest?

All 8 comments

I have the same problem, it transpiles correctly, but ignores type errors. I am not using the --transpileOnly flag. Also i can confirm that it works as expected with ts-node 8.5.4.
I am using yarn so i created a resolution that temporarily fixed the problem.

  "resolutions": {
    "ts-node-dev/ts-node": "8.5.4"
  }

I have the same problem, it transpiles correctly, but ignores type errors. I am not using the --transpileOnly flag. Also i can confirm that it works as expected with ts-node 8.5.4.
I am using yarn so i created a resolution that temporarily fixed the problem.

  "resolutions": {
    "ts-node-dev/ts-node": "8.5.4"
  }

Nice!

I found the problem. This commit added backward compatibility with an old (i think), deprecated, flag --type-check https://github.com/TypeStrong/ts-node/commit/8834d645849f5b9a6eb377aaa32e92dc094d40f8. When ts-node-dev initializes its options, if this flag is missing, it becomes false by default, which as a consequence disables type checking. If you add the --type-check flag, then type checking is working.
As a fix i think we should remove this option completely, we can also make it true by default, but since it's deprecated...
@whitecolor what do you suggest?

Also worth noting that when I run tsnd/ts-node-dev globally (npm -i -g / yarn global add), it behaves differently than when it's installed as a dependency in a project (node_modules/.bin/tsnd). For some reason the global instance respects type-checking but the project scoped one doesn't 😕 (both instances are the same version 1.0.0-pre.44).

@wsmd You might have an older version of ts-node installed globally?

That's a really good guess, unfortunately, ts-node in both locations is at 8.10.1. Fwiw, both global and local typescript/tsc are also on the same version, and I'm using yarn.

> /path/to/global/.bin/tsnd --version
v8.10.1
> /path/to/my_project/node_modules/.bin/ts-node --version
v8.10.1

Same issue,,luckily the current workaround for adding the --type-check flag works:

"dev": "ts-node-dev --type-check --respawn src/index.ts"

versions:
```
"ts-node": "^8.10.2",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.9.5"

Will be fixed in the nearest published.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JaLe29 picture JaLe29  Â·  9Comments

pvtri96 picture pvtri96  Â·  10Comments

kachkaev picture kachkaev  Â·  11Comments

jraoult picture jraoult  Â·  3Comments

timsuchanek picture timsuchanek  Â·  6Comments