Question

I have a set of typescript files which are compiled into a *.d.ts file, it keeps erroring for me though:

systems.debug.d.ts(280,41): error TS2094: The property 'Models' does not exist on value of type 'Systems'.

The declaration looks like this:

declare module Systems.Services.Stuff {
    class DefaultHubService {
        public Send(entry: Systems.Models.IEntry, successCallback: Function, failureCallback: Function): void;
    }
}

This occurs on line 280 (systems.debug.d.ts), and the thing it is struggling to reference is:

declare module Systems.Models {
    interface IEntry {
        Version: string;
        Content: KnockoutObservableString;
        DateCreated: KnockoutObservableDate;
        CreatorAccountId: KnockoutObservableString;
    }
}

This is on line 239 (systems.debug.d.ts), so I find it strange and don't know how to fix the issue. As the interface is included before the service it should to my knowledge work unless there is some quirk with Typescript. Can anyone shed any light on the error?

== Edit ==

Just providing some extra information incase it helps diagnose the issue...

The actual implementations look like this:

// Systems/Services/Stuff/default-hub-service.ts
module Systems.Services.Stuff {
    export class DefaultHubService {
        public Send(entry: Models.IEntry, successCallback: Function, failureCallback: Function): void
        {
            // Do something here
        }
    }
}

// Systems/Models/ientry.ts
module Systems.Models {
    export interface IEntry {
        Version: string;
        Content: KnockoutObservableString;
        DateCreated: KnockoutObservableDate;
        CreatorAccountId: KnockoutObservableString;
    }
}

There are no references in the individual files, as I have a root level reference file which contains all external references to use, and as this is included first within the compilation arguments it provides all external dependencies (i.e knockout.d.ts, jquery.d.ts etc).

I am using Typescript 0.9.0.1, and compile by calling tsc.exe directly from my build script. Finally the javascript output file is created without error so I have a systems.debug.js which compiles fine, however with the declaration flag its only the d.ts file which throws errors.

Was it helpful?

Solution 2

FOUND OUT WHAT WAS CAUSING IT!

Wow this is a crazy one... and I am not sure I fully understand it, as I found it by fluke.

I have a file like so:

module Systems.Services.Systems
{
    export class GameSystemService
    {
        // stuff
    }
}

Now by when trying out in typescript playground (as that had same errors as me), I accidentally deleted this one and all errors went away. Then put it back and tried deleting others and the errors stayed... So I knew it must be something to do with this...

Now I assume the error is because the module name is Systems.Services.Systems and somehow when it compiles the declaration for this, it freaks out because it must think the 2nd Systems is the same as the first or something.. I am not too sure what is causing Typescript to blow up on everything else, but I fixed it by renaming it to:

module Systems.Services.GameSystems

Then everything worked fine. Not sure if this is classed as a bug in typescript or a coding problem on my end, as I was not aware of any issue having a namespace which repeated the names...

Anyway that fixes it... crazy... thanks for your help guys!

OTHER TIPS

I don't get an error when I try your code - here is the complete example I am using:

declare class KnockoutObservableString {}
declare class KnockoutObservableDate {}

declare module Systems.Models {
    interface IEntry {
        Version: string;
        Content: KnockoutObservableString;
        DateCreated: KnockoutObservableDate;
        CreatorAccountId: KnockoutObservableString;
    }
}

declare module Systems.Services.Stuff {
    class DefaultHubService {
        public Send(entry: Systems.Models.IEntry, successCallback: Function, failureCallback: Function): void;
    }
}

var x = new Systems.Services.Stuff.DefaultHubService();
var y: Systems.Models.IEntry;

I tried this in the TypeScript Playground and also in Visual Studio with the 0.9.0.1 TypeScript Visual Studio Extension. In Visual Studio I separated the ambient declaration into a file named systems.debug.d.ts and put the use of that declaration in app.ts.

Since you are compiling in multiple steps perhaps the issue is The .d.ts definitions are not exported in the generated .d.ts i.e. say you have a.d.ts as :

interface Foo{
   var boo:number;
}

and you have a .d.ts files b.ts:

///<reference path="a.d.ts"
   class Bar implements Foo{
      boo:number; 
   }

and you compile as:

tsc a.d.ts b.ts --out out.js --declaration 

the file out.d.ts will not have interface Foo inside it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top