2

Closed

typescript 1.0 broke AMD declared Modules.

description

An example: knockout.mapping.d.ts had the following declaration:

    declare module "knockout.mapping" {
        export = KnockoutMapping;
    }
I could then include
    import mapper = require('knockout.mapping');
but this fails now with "Could not find symbol mapper". when using mapper.fromJS(..)

So question is, is there a new way in 1.0 that such modules should be defined?

This worked fine in 9.7.x (The release candidate).

Reproduce by adding nuget packages for knockout mapping and try import and use it.
Closed Apr 4 at 11:23 PM by danquirk

comments

pksorensen wrote Apr 4 at 8:48 AM

Seems that the solution is to change :

declare module "knockout.mapping" {
export = mapping;
}
declare var mapping: KnockoutMapping;

Would love a comment on if this is the way to do it and I will update the type definition.

danquirk wrote Apr 4 at 11:23 PM

Yes this is working as intended. As it is currently written the knockout.mapping.d.ts defines an ambient external module named 'knockout-mapping.' This module export='s the interface type KnockoutMapping. So when you require 'knockout-mapping' the identifier that is bound to that (ie mapper) is now an interface, not an instance. So you can use mapper in type positions but not value positions as is the case with mapper.fromJS(). With the change you noted in your comment you have now defined an instance of type KnockoutMapping named mapping. Now this is the thing that gets bound against when require'd and of course an instance of type KnockoutMapping does have a fromJS method on it that can be called. I'm unfamiliar with this library in particular but if what it is actually doing is exporting an instance of that type then yeah your update is correct.

pksorensen wrote Apr 5 at 8:14 AM

Thanks.

The library exposes the fromJS() methods on the export object.