I'm trying to mock a class of a third party library which contains a protected
property and have got an error message.
here's a small reproducible example:
class WithProtected {
protected property: number = 1
}
class Derived implements WithProtected {
property = 3
}
which outputs the following error message:
Class 'Derived' incorrectly implements class 'WithProtected'. Did you mean to extend 'WithProtected' and inherit its members as a subclass?
Property 'property' is protected but type 'Derived' is not a class derived from 'WithProtected'.(2720)
I'm kinda stuck to this mocking because the third party lib is Cocos Creator and doesn't live in the node_modules
library. The only way Typescript is working with it is because it is linked via a path
entry in the tsconfig.json
file of the project.
So I'm not able to use the mocking out of the box from jest.
Also, as I cannot import directly from the lib itself, I have to write a fair amount of mock without importing members directly from 'cc' but with the import type {} from 'cc'
which doesn't allow me to extend
said classes and implement only the mocks.
Maybe too much details on this but if I could at least find a way to implement
a class which contains a private prop, this would probably save me!