question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript Node types "leak" into a project using PIXI with v6

See original GitHub issue

Expected 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
qtikicommented, Mar 10, 2021

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 inside util. That way TypeScript can still validate that the exported url types are in fact compatible with the Node types.

I’ll see if I can whip up a PR for this.

0reactions
qtikicommented, Mar 10, 2021

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 to querystring too. Not the prettiest solution but it should work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Node types "leak" into a project using PIXI with v6.1.0
Adding PIXI to a TypeScript project should not add Node types to the project. Current Behavior. Node types are included from @pixi/core index.d....
Read more >
How to get typescript type completion for Pixi 6 native module?
First of all, if you look at the types installed by pixi.js in node_modules/pixi.js/index.d.ts you will find that it is mostly empty, ...
Read more >
pixi-stats - npm
pixi -stats. JavaScript Performance Monitor. This class provides an info box that will help you monitor your code performance.
Read more >
@pixi-spine/runtime-3.7 | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
TypeScript 2.0, pixi.js, and Webpack - Proof By Example
How to get a simple pixi.js project started with TypeScript 2.0 and ... Have the latest node.js installed and in your path. v6.3.1...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found