4

I'm trying to create some definition files for a personal project. (I'm recreating the context here with different class/module names, so the modeling may not make a whole lot of sense).

I have the following interface definition file, that has no dependencies, and compiles fine:

// File: automobile.d.ts
declare module Transport {
    interface Automobile {
        // ... variables and functions
        accelerate(direction:String):Boolean;
    }
}

However, in this file, when I try to reference Automobile in this file within the same Transport module, I get a Cannot find name 'Automobile'.

// File: automobile_collection.d.ts
declare module Transport {
    interface AutomobileCollection {
        size:Number;
        getItemAt(index:Number): Automobile;
    }
}

I've tried exporting the interface, but that didn't help. Any ideas what I'm doing wrong?

4
  • 1
    I'm not able to reproduce your issue in visual studio or with tsc 1.5-beta. How are you compiling this? By the way, you should use the primitive types number, string, boolean (lowercase) instead of the interfaces as using the interfaces can lead to problems. Commented Jul 10, 2015 at 14:33
  • Interesting, I'm using Webstorm's Typescript plugin. I'll give tsc a shot and see if I still get errors. Maybe this is Webstorm intellisense problem. And, thanks, I had no idea about the primitive type thing. Will replace those too. Commented Jul 10, 2015 at 14:35
  • Wow okay thanks for the tip. My whole project compiles just fine using tsc. I guess it's a webstorm issue. At least this informs my Google searches more. Thanks! Commented Jul 10, 2015 at 14:45
  • Figured it out, and posted an answer to my own question Commented Jul 10, 2015 at 15:08

1 Answer 1

2

Thanks to David, I figured out that it wasn't a compiler error, because my project compiles fine using tsc.

It turns out you need to add /// <reference path="./automobile.d.ts"/> at the top of automobile_collection.d.ts to get Webstorm to intelligently figure out referenced types.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah! Ok, that makes sense. I'm so used to not adding /// <reference ... /> nowadays that this solution didn't occur to me. I guess Webstorm doesn't have the functionality that does that automatically yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.