0

I'm trying to extend a class that exists as a node_module.

My extended class has no access to the parent's prototype.

Here's a link to a repro:

https://bitbucket.org/IamHttP/repro-types/src/master/

Here's an image that shows this behaviour in WebStorm

As you can see, one has access to destroy() and one does not.

enter image description here

4
  • 1
    Did you run it to check if it is weird behavior of WebStorm ? Commented Feb 21, 2020 at 15:39
  • yea ofcourse :) typescript itself is not compiling even from the command line. Commented Feb 21, 2020 at 20:05
  • Do you think you could reproduce this in a web IDE so that people who want to help can do so without npm installing code on their machines? Also, as mentioned in How to Ask, it's a good idea that any minimal reproducible example example be included as text in your question, not only as an external link or as a picture. Thanks! Commented Feb 22, 2020 at 2:28
  • Thanks for hte input @jcalz - I was sure the issue is related to a node module, so I guess I had to provide a real example with a node_module. I'll take note for future questions. I tried to be as informative as possible :) Commented Feb 22, 2020 at 9:28

2 Answers 2

3

Your type definition for Entity is not properly exported from the first package. Use Go to Definition on game-platform in your second project and you'll see this in your first package's types:

import Entity from 'lib/ECS/Entity';
import entityLoop from 'lib/ECS/util/entityLoop';
import ObjectPool from 'lib/ObjectPool/ObjectPool';
import GameCanvas from 'lib/GameCanvas/GameCanvas';
import Engine from 'lib/Engine/Engine';
...

It is typed as any on import in the consuming project, because that path cannot be resolved. Changing it to this in the first package makes it work as expected:

import Entity from './lib/ECS/Entity';
Sign up to request clarification or add additional context in comments.

3 Comments

Wow good find. I also took a look. Looks like this might be a good idea to add a stricter configuration. My typescript will warn me on bad exports and imports that don't have types.
No implicit any might do it. You can use eslint to disallow any at all.
Thanks! I started investigating down that path myself, I found a closed issue with typescript that it does not re-write the import paths in generated files - this is really unfortunate as I'd like to use alias paths in my projects instead of ../../../../../ hell - Much appreciated @JoshWulf
0

destroy method is probably private.

class A {
  private a;
  constructor() {

  }
}

class B extends A {
  constructor() {
    super();
  }
}

const b = new B();
b.a; // Error

1 Comment

Thanks, but it's not actually private, I control both packages. also, the JS part does work (if compile by force I have access to destroy in real JS code)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.