Ts-node: Type is incorrect in ts-node, but correct everywhere else

Created on 18 Apr 2019  路  6Comments  路  Source: TypeStrong/ts-node

I'm using a project based of the Typescript-babel starter

open source reproduction: https://github.com/NullVoxPopuli/static-route-paths/blob/master/tests/index.ts#L57
(the actual code in this case)

$ yarn type-check
yarn run v1.15.2
$ tsc --noEmit
Done in 1.17s.
 $ yarn build
yarn run v1.15.2
$ yarn build:types && yarn build:js
$ tsc --emitDeclarationOnly
$ babel src --out-dir dist --extensions ".ts"
Successfully compiled 3 files with Babel.
Done in 1.85s.



md5-6fd24d212a627074abc4d97a92e3b452



{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "esnext",
"module": "commonjs",
"lib": ["es6", "dom"],
"declaration": true,

"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,

},
"include": [
"src/*/"
],
"exclude": [
"node_modules",
"dist",
]
}
```

bug

Most helpful comment

I just spent few hours addressing this issues. I was not expecting ts-node to behave differently than tsc, so I assumed there was something wrong with my tsconfig.json file. After digging and trying different things, finally found that there is discrepancy between tsc and ts-node. I think files should be included by default and excluded by choice. It's a bit odd for ts-node to behave differently than tsc in default settings.

All 6 comments

I'm having a very similar issue.

My tsconfig.json has an "include": ["./types", ./"src"] in it.

I have type defs in the types directory to alias some modules that we're loading in our webpack.config.ts file. When I run tsc, all checks out. But, when I try to run webpack, which uses ts-node behind the scenes to load in webpack, it is throwing type errors for things I know I have in the types folder.

My hunch after digging around a bit is this PR. https://github.com/TypeStrong/ts-node/commit/e009d792c52b56fe5ba8f5cf8965dfb03916b3dd

I'm not sure why this line exists in that PR?

if (!files) {
   config.files = [];
   config.include = []; // this one?
}

If I comment it out, it properly includes all the type defs I have...

The only solution I have found is to use /// refs at the top of my webpack config to manually include the types.

Thanks! I'll do what I can to help debug the issue further for y'all if needed.

Thanks for the investigation. It sounds like I prematurely marked this as a bug, it鈥檚 actually a feature. There鈥檚 a section in the README that explains what to do if you鈥檙e types are missing. This module doesn鈥檛 include everything by default because it slows startup for a simple script like Webpack (you鈥檇 end up loading the entire project into TypeScript).

I just spent few hours addressing this issues. I was not expecting ts-node to behave differently than tsc, so I assumed there was something wrong with my tsconfig.json file. After digging and trying different things, finally found that there is discrepancy between tsc and ts-node. I think files should be included by default and excluded by choice. It's a bit odd for ts-node to behave differently than tsc in default settings.

I agree with @joonhocho, this is an actual _unexpected_ behavior.
When tsc && node main.js works, you _expect_ ts-node main.ts to work as is, since that's the very purpose of this (amazing btw) lib.

Performance-oriented features that _break_ expectations should be opt-in.

Webpack is not used on the backend (or very rarely), and because ts-node decided to ease performance tuning, we're loosing time with a _false negative_, trying to figure out what mistake we did in our code, before heading to the bottom of the github readme.

And I think you'll continue to have issues from people rightfully mistaking that feature for a bug.

I may sound vehement, but I'm not, and I'd like to thank you for the great work and great care, even in performance related issues like this one, that led to a complicated and necessarily opinionated design decision. 馃檪

Real problem is that default settings works only until it starts breaking, which is what happened to me. Everything was working fine, but then my project size grew and it stopped working.

--files should be default true. Cause too many problems.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KiaraGrouwstra picture KiaraGrouwstra  路  3Comments

conordickinson picture conordickinson  路  4Comments

cibergarri picture cibergarri  路  3Comments

joshua-tj picture joshua-tj  路  3Comments

sodiumjoe picture sodiumjoe  路  4Comments