Here is my tsconfig.json:
{
"compilerOptions": {
"module": "umd",
"target": "esnext",
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"skipLibCheck": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": false,
"declaration": true,
"sourceRoot": "src",
"baseUrl": "src",
"outDir": "dist",
"strict": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"lib": [
"es2015",
"es2017.object",
"dom"
],
"typeRoots": [
"node_modules/@types",
"types"
],
"plugins": [
{
"name": "typescript-tslint-plugin"
}
]
},
"typedocOptions": {
"mode": "modules",
"out": "docs"
},
"include": [
"src"
]
}
Code sample:
const timeout = setTimeout(() => {}, 0);
if (timeout.unref) {
timeout.unref();
}
With 8.1.1 it works fine, with 8.2.0 and 8.3.0 it fails with:
error TS2339: Property 'unref' does not exist on type 'number'.
Even though project has @types/node installed and tsc -b works fine and tslint in strict mode doesn't complain either.
Seems like https://github.com/TypeStrong/ts-node/commit/9691206def28405d4e53c5a7753f96d15be46e79 then, which itself was an unexpected breaking change in 8.1.0, it can be re-added in 9.0.
Can you check by running on 8.0.2?
Personally, this looks more like you added “dom” to the list of types than a change in versions. I’m pretty sure if you remove DOM it’ll work.
8.0.2 works fine too.
I can't remove DOM because project targets both environments and a lot of other things will fail to compile because of that.
Can you create a reproduction? The change I pointed out, which is the only change of code between the version you say broke, didn’t exist on 8.0.2 which is why I asked you to test it. If that works, there must be something else going on.
Closing because it this _should_ be failing. In browsers setTimeout returns a number and you're using the types from DOM (browsers).
I believe ts-node should be running successfully anything that compiles with TypeScript compiler. That code compiles in strict mode with TypeScript and runs both in Node.js and Browser.
Moreover, explicit check for property narrows down timeout inside of if branch, hence this code if perfectly correct even if used with DOM types and without any Node.js types at all (while I do have @types/node installed in the project).
Please reopen this issue, I will try to create standalone reproducible example in separate repo.
I'll take a quick look, you are correct. I'd really appreciate any sort of help in the future, usually I'm commenting without having the capacity to fully test. Apologies for closing this without fully understanding.
Appears to be resolved with https://github.com/TypeStrong/ts-node/releases/tag/v8.4.1.
Verified, 8.4.1 works, thanks!
@blakeembrey This change triggered a big loss in performance when watching files (with mocha for instance). Would there be another way to solve the problem ?
I'm stuck at version 8.4.0 now (opposite of nazar-pc 😅)
Hi!
We are having this same issue on version 8.8.1 running in node environment. We get the same error using _latest_ version but can resolve it using version 8.4.1 as pointed out working:
Verified, 8.4.1 works, thanks!
@hilleer I believe this is resolved in the new v9.0.0: https://github.com/TypeStrong/ts-node/releases/tag/v9.0.0
@hilleer I believe this is resolved in the new v9.0.0: https://github.com/TypeStrong/ts-node/releases/tag/v9.0.0
@cspotcode yes - it seem to be working again with latest version. Thanks for fixing and notifying about it!
Most helpful comment
@hilleer I believe this is resolved in the new v9.0.0: https://github.com/TypeStrong/ts-node/releases/tag/v9.0.0