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

  • SEARCH
  • Home
  • 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 9151453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:48:21+00:00 2026-06-17T11:48:21+00:00

I’ve got two classes that need to know one another’s members. In C++ I’d

  • 0

I’ve got two classes that need to know one another’s members.

In C++ I’d use a forward declaration.

What do I have to do in typescript?

  • 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-17T11:48:23+00:00Added an answer on June 17, 2026 at 11:48 am

    I’m not sure, but I think you’re trying to solve a problem that doesn’t exist. This is perfectly valid in typescript:

    class A{
        b=new B();
        func(){
            alert(this.b.member);
        }
    }
    class B{
        member="hello there";
    }
    var a=new A();
    a.func();
    

    As you can see, you can use the class B before it is defined and access its members from within class A. The same applies to functions:

    var a=()=>{
        alert("function a");
        b();
    }
    
    var b=()=>{
        alert("function b");
    }
    
    a();
    

    This should compile fine. Please note that a can only be called after b is actually defined. This won’t work:

    var a=()=>{
        alert("function a");
        b();
    }
    a();
    
    var b=()=>{
        alert("function b");
    }
    

    You don’t need forward declarations in Typescript. Just imagine that they are automatically generated for your code.

    The problem becomes more complex when you need to mix Javascript and Typescript. Since all your Typescript code is statically type-checked by the compiler, interfacing Javascript frameworks is not that simple.

    All variables, functions and “classes” added to your scope need to be declared before you can use them. Let’s assume that you need jQuery for your Typescript project. All the jQuery magic is done with the global variable “$” but even if you’ve added the jQuery script to your html site, you can’t just refer to “$” in your Typescript code. This is where declaration files are used. By adding the line

    /// <reference path="jquery.d.ts"/>
    

    to the top of your Typescript file, you inform the compiler about all the jQuery code that is available. .d.ts files for the most commonly used Javascript frameworks can be found here: https://github.com/borisyankov/DefinitelyTyped

    The last two lines are a nice example of the syntax of .d.ts files:

    declare var jQuery: JQueryStatic;
    declare var $: JQueryStatic;
    

    Now the compiler knows that two global variables named “$” and “jQuery” are available to you. Moreover if you’re using VisualStudio these declaration files will allow for fantastic intellisense support.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am confused How to use looping for Json response Array in another Array.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.