I've got a browser app, and I'm trying to ensure that @types/node aren't included as part of typescript's compilation environment. I had this working with AVA v2, but AVA v3 is forcing @types/node, causing compilation issues.
Here's a example:
// src/foo.ts
export default function() {
// If @types/node is loaded, this errors on compilation
// with "NodeJS.Timeout is not assignable to number"
let timeout: number = setTimeout(() => console.log("Ping"), 2000);
}
// tests/foo.test.ts
import test from "ava";
//...
// tsconfig.json
{
"compilerOptions": {
// Prevent TS from automatically loading ambient definitions from node_modules/@types
// except those explicitly listed here
"types": [],
},
"include": ["src"],
}
// tsconfig.test.json
{
"extends": "./tsconfig",
"include": ["src", "tests"]
}
The project compiles correctly with tsconfig.json but fails with tconfig.test.json, because @types/node gets pulled in. The culprit is this line, which was added by #2154:
/// <reference types="node"/>
That causes @types/node to be pulled in explicitly, and foo.ts fails to compile. (I've confirmed that removing that line from node_modules/ava/index.d.ts fixes the compilation)
The only workaround I could come up with from my end, (other than adding @types/node to my non-test code and changing the annotations) would be to move to a Typecript project references setup, which is non-trivial.
I've got a browser app, and I'm trying to ensure that
@types/node
aren't included as part of typescript's compilation environment. I had this working with AVA v2, but AVA v3 is forcing@types/node
, causing compilation issues.Here's a example:
The project compiles correctly with
tsconfig.json
but fails withtconfig.test.json
, because @types/node gets pulled in. The culprit is this line, which was added by #2154:That causes
@types/node
to be pulled in explicitly, andfoo.ts
fails to compile. (I've confirmed that removing that line fromnode_modules/ava/index.d.ts
fixes the compilation)The only workaround I could come up with from my end, (other than adding @types/node to my non-test code and changing the annotations) would be to move to a Typecript project references setup, which is non-trivial.