Closed Codeluck closed 6 years ago
Can you paste here an example code that fails? It sounds like an issue with types as understood by the compiler.
Here's a working example in the test cases.
Here is an example:
In Layer.ts (Assuming IGalleryItem is imported correctly):
export const LayerData = types.model("Layer", {
x: 0,
y: 0,
width: 0,
height: 0
});
class LayerCode extends shim(LayerData) {
@action
postLoadingAction(isError?: boolean, data?: IGalleryItem) {
if (!isError) {
// Some code goes here
}
}
}
export const Layer = mst(LayerCode, LayerData);
export type Layer = typeof Layer.Type;
In SVGLayer.ts:
const SVGLayerData = Layer.props({});
class SVGLayerCode extends shim(SVGLayerData, Layer) {
@action
postLoadingAction(isError?: boolean, data?: IGalleryItem) {
if (data !== undefined && data.parser !== undefined) {
// Do some init stuff
}
// ERROR HERE ("super keyword unexpected here")
super.postLoadingAction(isError, data);
}
}
export const SVGLayer = mst(SVGLayerCode, SVGLayerData, 'SVGLayer');
export type SVGLayer = typeof SVGLayer.Type;
Here is a piece of package.json for your information:
"classy-mst": "^0.4.0",
"mobx": "^4.1.0",
"mobx-react": "^5.0.0",
"mobx-react-devtools": "^5.0.1",
"mobx-state-tree": "^2.0.2",
"mst-middlewares": "^2.0.2",
Thank you!
I just checked that the above code compiles fine. I'm using TypeScript 2.8.3 to compile to ES5 with CommonJS modules. Also tested with ES6. Not using Babel.
Has the problem gone away by now, or does it come from TypeScript or Babel or the JavaScript environment itself? Version 0.4.1 may have fixed the problem.
I think the issue was caused by my personal environment. Thanks!
Hello,
I used an example of inheritance you provided. But I got a compile time error like: "super keyword unexpected here" when trying to call
super.myMethod()
frommyMethod()
of a child class. Do you have any ideas why could it be? And I am using a TypeScript. So far I put my logic into a parent class as a workaround.