8

How do i get access to classes in another .ts file in TypeScript?

e.g.

app.ts

window.onload = () => {
   /// <reference path="TilingEngine/SofRenderer.ts" >
   var drawingTool = new SofRenderer();
};

TilingEngine/SofRenderer.ts

class SofRenderer {
}

Fails to compile, with the error:

Could not find symbol 'SofRenderer'.

See also

1 Answer 1

13

Your reference comment should be at the top of your file and be self-closing. Like this:

///<reference path="TilingEngine/SofRenderer.ts" />
window.onload = () => {
   var drawingTool = new SofRenderer();
};
Sign up to request clarification or add additional context in comments.

3 Comments

When i first read the answer, i read it as "Your reference comment at the top should be self-closing". Wasn't until another reading that i noticed the should be at the top.
It is quite strict about this for some reason :)
you also need to decorate the classes/interfaces/etc with the keyword 'export' in your source .ts file.

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.