0

I have a file module.d.ts with declaration

declare module "ArrayItem" {import out = require("models/ArrayItem"); export = out;}

Now I have a file Array.ts and the first line is

/// <reference path="../module.d.ts" /> 
import array = require("ArrayItem").

But this is not working. I got script error.

If I use,

/// <reference path="../module.d.ts" /> 
import array = require("models/ArrayItem")

Then I did not get any error.

What is the issue in module loading here?

If I have a module.d.ts, then the arrayitem module should be loaded from require("arrayitem").

Correct? Or should I always the correct path for ArrayItem?

I am confused here. Can someone throw help here?

1 Answer 1

1

If you are the owner of ArrayItem.ts then you don't need module.d.ts. Just reference the module directly.

You are getting a runtime error but not a compiler error because your runtime is trying to load ArrayItem.js for the current path and not from models/ArrayItem. There is no point in your module.d.ts file since it is only a wrapping of the definitions (but not code) in the typescript module, which your already going to pick up with a direct reference to the module.

So, don't use the /// and import using require("models/ArrayItem").

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

3 Comments

ok..so I should always say import array = require("models/ArrayItem") even though I have module.d.ts file? Can you please elaborate what should I do here?
You have one typescript module referencing another typescript module so there is no need for module.d.ts. You would only do something like that if you were working with a javascript library in typescript.
Got it...I have to make some changes. Thanks,

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.