TypeScript Node types "leak" into a project using PIXI with v6
See original GitHub issueExpected Behavior
Adding PIXI to a TypeScript project should not add Node types to the project.
Current Behavior
Adding PIXI to a TypeScript project adds a dependency to Node types.
For example this project compiles successfully:
tsconfig.json
{
"compilerOptions": {
"lib": [
"dom",
"esnext",
"scripthost"
]
},
"include": [
"src"
]
}
src/index.ts
const timeout: number = setTimeout(() => {
console.log('hello world');
}, 100);
However after just adding pixi.js
to the project without modifying the code at all the setTimeout
return value is no longer assignable to a number
as it’s type changes to NodeJS.Timeout
and compiling gives the following error:
src/index.ts:1:7 - error TS2322: Type 'Timeout' is not assignable to type 'number'.
1 const timeout: number = setTimeout(() => {
~~~~~~~
Possible Solution
Remove the type dependency to Node. This is most likely caused by a Node type reference in one of PIXI’s dependencies rather than PIXI itself. I haven’t yet investigated this in more detail so I can’t say for sure what is causing this and how to fix it.
Steps to Reproduce
Run the following commands to create the empty project and copy tsconfig.json
and src/index.ts
from the example above:
yarn init
yarn add typescript
yarn add pixi.js
After the project is setup run yarn tsc --noEmit
to get the error.
Environment
pixi.js
version: 6.0.0- TypeScript version: 4.2.3
- OS & Version: Windows 10
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
I came to the same conclusion after some searching. I think it would be better to move the Node types to a dev dependency and re-declare the
url
types insideutil
. That way TypeScript can still validate that the exportedurl
types are in fact compatible with the Node types.I’ll see if I can whip up a PR for this.
I made the PR. The types for the
url
package were a bit more complex than I originally thought and they also had a dependency toquerystring
too. Not the prettiest solution but it should work.