charto / classy-mst

ES6-like syntax for mobx-state-tree
MIT License
91 stars 5 forks source link

super keyword unexpected here #5

Closed Codeluck closed 6 years ago

Codeluck commented 6 years ago

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() from myMethod() 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.

jjrv commented 6 years ago

Can you paste here an example code that fails? It sounds like an issue with types as understood by the compiler.

jjrv commented 6 years ago

Here's a working example in the test cases.

Codeluck commented 6 years ago

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!

jjrv commented 6 years ago

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.

Codeluck commented 6 years ago

I think the issue was caused by my personal environment. Thanks!