This is a migrated thread and some comments may be shown as answers.

Typescript Inheritance for Binders

9 Answers 139 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
mgs
Top achievements
Rank 1
mgs asked on 20 Jun 2013, 11:18 AM
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

9 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 20 Jun 2013, 11:30 AM
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!
0
mgs
Top achievements
Rank 1
answered on 20 Jun 2013, 12:34 PM
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
0
mgs
Top achievements
Rank 1
answered on 20 Jun 2013, 12:50 PM
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
0
mgs
Top achievements
Rank 1
answered on 20 Jun 2013, 12:51 PM
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
0
Atanas Korchev
Telerik team
answered on 20 Jun 2013, 01:42 PM
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!
0
mgs
Top achievements
Rank 1
answered on 20 Jun 2013, 01:53 PM
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
0
Atanas Korchev
Telerik team
answered on 20 Jun 2013, 02:02 PM
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!
0
mgs
Top achievements
Rank 1
answered on 20 Jun 2013, 02:12 PM
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
0
Atanas Korchev
Telerik team
answered on 20 Jun 2013, 02:37 PM
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!
Tags
General Discussions
Asked by
mgs
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
mgs
Top achievements
Rank 1
Share this question
or