Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:33:20+00:00 2026-06-12T13:33:20+00:00

Assume the following class definition using TypeScript in Animal.ts: module Animals { export class

  • 0

Assume the following class definition using TypeScript in Animal.ts:

module Animals
{
    export class Animal { }    
}

If I want to create a Dog class in a seperate file, say in Dog.ts using this code:

module Animals
{
    export class Dog extends Animal { }
}

the name “Animal” does not exist in the current scope, is the error I get in class definition Dog.

Adding the following line to Dog.ts

/// <reference path="Animal.ts"/>

fixes the compilation error but why is this necessary, if both classes are being defined within the same module?

In other words, I want module declarations to span across files with each class or interface definition in their own file. Is this even best practice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:33:22+00:00Added an answer on June 12, 2026 at 1:33 pm

    The /// reference is necessary because the compiler needs to know where Animal is defined somehow. It can’t know what source file it’s in without you telling it where to look.

    I’m not sure this is a best practice per se (would need to know more about your application) but I hardly think it’s an anti-pattern so I think you can feel free to do that. Modules in TypeScript are deliberately open ended to allow for this sort of pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using boost python I need create nested namespace. Assume I have following cpp class
Lets assume following classes definition: public class A { public final static String SOME_VALUE;
Assume the following: we have class B, which is a private class nested inside
Background: Let's assume I've got the following class: class Wrapped<T> : IDisposable { public
Assume I have the following classes class Genre { static hasMany=[author:Author] } class Author{
Assume that we have the following code: class Program { static volatile bool flag1;
Lets assume we have the following code: abstract class Base1 { protected int num;
Let's assume I have the following code: public class MainClass { public static void
In Java, assume I have the following class Container that contains a list of
I'm developing a shared library. Let's say I have the following class definition: class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.