Skip to content

Runtime error for two classes in one ts file. #8572

Closed

Description

TypeScript Version:

1.8.10

Code

export class BaseLayoutModel extends BaseModel {
    constructor(attributes?: any, options?: any) {
        super(attributes, options);
    }
}

export class BaseModel extends Backbone.Model {
    constructor(attributes?: any, options?: any) {
        super(attributes, options);
    }

    destroy(options?: Backbone.ModelDestroyOptions): any {
        const opts = _.extend({
            contentType: "application/json",
            dataType: "text"
        }, options || {});
        super.destroy(opts);
    }
}

Expected behavior:

Actual behavior:
Runtime error. BaseModel is undefined

Activity

  1. zpdDG4gta8XKpMCd commented on May 12, 2016

    @zpdDG4gta8XKpMCd

    in your code BaseModel is declared lexically after BaseLayoutModel

    in the compiled code it means that BaseModel is used before being initialized

    try swapping the declarations (BaseModel class should come first)

  2. vitaliy-leschenko commented on May 12, 2016

    @vitaliy-leschenko
    Author

    I know about “why it failed”. But this code translated to JS without any errors.

  3. Arnavion commented on May 12, 2016

    @Arnavion

    Duplicate of #4341 and #5207 which should be fixed by #4343

  4. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions