Typescript Inheritance for Binders

10 posts, 0 answers
  1. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 20 Jun 2013 Link to this post

    Hello Atanas,

    this is a new post, describing the problem that we started to talk about in the "definition file for Typescript" thread.

    Create a simple Typescript file test1.ts and compile for AMD
    export var NAME = "mike";
    Create another Typescript file test2.ts with a shortened version of your code. It compiles perfectly.
    /// <reference path="kendo.all.d.ts" />
     
    module kendo.data.binders {
        export class custom extends Binder {
          constructor(element: Element, bindings: { [key: string]: Binding; }, options?: any) {
             super(element, bindings, options);
          }
       }
     }
    Now create another Typescript file test3.ts. Regarding your code it is the same as test2. It additionally imports test1.
    /// <reference path="../dts/kendo.all.d.ts" />
     
    import T1 = module("test1");
     
    module kendo.data.binders {
       export class custom extends Binder {
          constructor(element: Element, bindings: { [key: string]: Binding; }, options?: any) {
             super(element, bindings, options);
          }
       }
    }
    Now there are problems, not being able to find Binder, Binding, etc.

    Michael G. Schneider
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 20 Jun 2013 Link to this post

    Hello,

    Are you sure the path to the definition file is correct? This looks like a wrong path issue. TypeScript probably can't find anything from the kendo namespace because it can't load the file. In any case sending us a complete project would help us pinpoint the problem.

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 20 Jun 2013 Link to this post

    Hello Atanas,

    the "../dts/" has been a copy/paste error. Of course, also in test3.ts there is the correct reference to your definition file. But I will prepare a complete project and send it later.

    Michael G. Schneider
  5. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 20 Jun 2013 Link to this post

    Hello Atanas,

    here is a sample project showing the problems. If you have Web Essentials installed, then saving test3.ts will show the errors. The same will happen when compiling on the command line.

    Thanks a lot in advance.

    Michael G. Schneider
  6. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 20 Jun 2013 Link to this post

    Hello Atanas, here is a sample project showing the problems. If you have Web Essentials installed, then saving test3.ts will show the errors. The same will happen when compiling on the command line. Thanks a lot in advance. Michael G. Schneider
  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 20 Jun 2013 Link to this post

    Hello Michael,

     Indeed there seems to be some issue when the import statement is used. For some reason one can no longer extend existing modules (such as kendo.data.binders). TypeScript treats them as a completely new module. I was able to reproduce the same behave with a very simple setup:

    kendo.all.d.ts:

    declare module foo {
        export class bar {
        }
    }

    declare module foo.bar {
    }

    test3.ts:
    /// <reference path="kendo.all.d.ts" />

    module foo {
        class baz extends bar { // Could not find symbol "bar"
        }
    }

    import T1 = module("test1"); // removing this line solves the problem

    I am completely at a loss why this happens and I couldn't find any information online why importing a module disallows extending other modules. The following two sound related though:

    http://stackoverflow.com/questions/14311801/typescript-internal-module-cannot-be-imported-unexpected-behavior
    http://stackoverflow.com/questions/15910131/using-import-breaks-extending-internal-modules


    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 20 Jun 2013 Link to this post

    Hello Atanas,

    thanks a lot for the answer. This situation is not new with v0.9. So even with v0.8 it was impossible to create binders by using inheritance, if AMD was part of the solution.

    So it seems as if creating a binding (probably also widgets itsself) is best not done by inheritance, but by the usual Javascript technique.

    This is something which brings me back to the other thread, asking for a change in the definition file, so "kendo.data.Binder.fn.init" can be coded.

    Michael G. Schneider
  9. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 20 Jun 2013 Link to this post

    Hi,

     Does manually adding the init statement to the kendo definition file help? It is the same as the "constructor".

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  10. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 20 Jun 2013 Link to this post

    Hello Atanas,

    yes, including a
    init(element, bindings, options): void;
    into class Binder will help. This is an issue similar to the one which I discussed with Alex on April 6th (see the other long thread). There it was "class Widget" which caused me the same problems.

    Michael G. Schneider
  11. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 20 Jun 2013 Link to this post

    Hello Michael,

    I've asked a question on stackoverflow about why this error occurs (looks like a TypeScript bug to me).

    We will patch our definitions to include the init method as well as the constructor. This would be available in the next official release.

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready