what is Difference between keyword new and :(colon) symbol while creating the new instance of a class The Next CEO of Stack OverflowWhat is the difference between Promises and Observables?What is the difference between declarations, providers, and import in NgModule?Import classes and external libaries in Angular2?TS2554: typescript issuecreating object without parameters in angular 4What's the difference between property instantiation methods esp. with respect to a service base class?Angular 5 Understanding External Class ImportsClasses and Interfaces with or without export keyword in Angular projectGeneric factory function with bounds doesn't always check existing constructorsCreate instance of object in typescript Angular 2

What difference does it make using sed with/without whitespaces?

Towers in the ocean; How deep can they be built?

Defamation due to breach of confidentiality

What is the process for purifying your home if you believe it may have been previously used for pagan worship?

What day is it again?

Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Lucky Feat: How can "more than one creature spend a luck point to influence the outcome of a roll"?

How do I fit a non linear curve?

What connection does MS Office have to Netscape Navigator?

Is Nisuin Biblical or Rabbinic?

What would be the main consequences for a country leaving the WTO?

How do you define an element with an ID attribute using LWC?

Are the names of these months realistic?

How can the PCs determine if an item is a phylactery?

Vector calculus integration identity problem

How to calculate the two limits?

What flight has the highest ratio of timezone difference to flight time?

Won the lottery - how do I keep the money?

Can you teleport closer to a creature you are Frightened of?

Is there a difference between "Fahrstuhl" and "Aufzug"?

Inductor and Capacitor in Parallel

Can Sneak Attack be used when hitting with an improvised weapon?

What's the commands of Cisco query bgp neighbor table, bgp table and router table?



what is Difference between keyword new and :(colon) symbol while creating the new instance of a class



The Next CEO of Stack OverflowWhat is the difference between Promises and Observables?What is the difference between declarations, providers, and import in NgModule?Import classes and external libaries in Angular2?TS2554: typescript issuecreating object without parameters in angular 4What's the difference between property instantiation methods esp. with respect to a service base class?Angular 5 Understanding External Class ImportsClasses and Interfaces with or without export keyword in Angular projectGeneric factory function with bounds doesn't always check existing constructorsCreate instance of object in typescript Angular 2










-1















I have 2 class i want to import one class in



Class students



export class students 
public avr=123;
constructor(a,b,c)



class college



import students from './commonwork'
export class college
constructor(public abc:students)



This way works fine.



But



when I try to create the instance of class with new keyword in College class either in constructor or any where inside the class



var studentinstance= new student()


I get the error as "Expected 3 arguments, but got 0.ts(2554)"



Can some one please explain the difference creating the instance with new keyword and :(colon)










share|improve this question
























  • The colon doesn't create anything, that just specifies the type of the parameter. If there's a students in Angular's DI, it will inject it for you. When you try to new up a student, you indeed do not provide the arguments required. It's unclear what part of this outcome was unexpected.

    – jonrsharpe
    Mar 7 at 18:09
















-1















I have 2 class i want to import one class in



Class students



export class students 
public avr=123;
constructor(a,b,c)



class college



import students from './commonwork'
export class college
constructor(public abc:students)



This way works fine.



But



when I try to create the instance of class with new keyword in College class either in constructor or any where inside the class



var studentinstance= new student()


I get the error as "Expected 3 arguments, but got 0.ts(2554)"



Can some one please explain the difference creating the instance with new keyword and :(colon)










share|improve this question
























  • The colon doesn't create anything, that just specifies the type of the parameter. If there's a students in Angular's DI, it will inject it for you. When you try to new up a student, you indeed do not provide the arguments required. It's unclear what part of this outcome was unexpected.

    – jonrsharpe
    Mar 7 at 18:09














-1












-1








-1








I have 2 class i want to import one class in



Class students



export class students 
public avr=123;
constructor(a,b,c)



class college



import students from './commonwork'
export class college
constructor(public abc:students)



This way works fine.



But



when I try to create the instance of class with new keyword in College class either in constructor or any where inside the class



var studentinstance= new student()


I get the error as "Expected 3 arguments, but got 0.ts(2554)"



Can some one please explain the difference creating the instance with new keyword and :(colon)










share|improve this question
















I have 2 class i want to import one class in



Class students



export class students 
public avr=123;
constructor(a,b,c)



class college



import students from './commonwork'
export class college
constructor(public abc:students)



This way works fine.



But



when I try to create the instance of class with new keyword in College class either in constructor or any where inside the class



var studentinstance= new student()


I get the error as "Expected 3 arguments, but got 0.ts(2554)"



Can some one please explain the difference creating the instance with new keyword and :(colon)







angular typescript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 18:12









Heretic Monkey

6,55863672




6,55863672










asked Mar 7 at 18:07









AkkiAkki

31




31












  • The colon doesn't create anything, that just specifies the type of the parameter. If there's a students in Angular's DI, it will inject it for you. When you try to new up a student, you indeed do not provide the arguments required. It's unclear what part of this outcome was unexpected.

    – jonrsharpe
    Mar 7 at 18:09


















  • The colon doesn't create anything, that just specifies the type of the parameter. If there's a students in Angular's DI, it will inject it for you. When you try to new up a student, you indeed do not provide the arguments required. It's unclear what part of this outcome was unexpected.

    – jonrsharpe
    Mar 7 at 18:09

















The colon doesn't create anything, that just specifies the type of the parameter. If there's a students in Angular's DI, it will inject it for you. When you try to new up a student, you indeed do not provide the arguments required. It's unclear what part of this outcome was unexpected.

– jonrsharpe
Mar 7 at 18:09






The colon doesn't create anything, that just specifies the type of the parameter. If there's a students in Angular's DI, it will inject it for you. When you try to new up a student, you indeed do not provide the arguments required. It's unclear what part of this outcome was unexpected.

– jonrsharpe
Mar 7 at 18:09













2 Answers
2






active

oldest

votes


















0














public abc:students doesn't create anything.¹ The :students part just assigns a type to abc. It doesn't create an instance of that type, it just says that if abc is going to refer to anything, it has to be of type students.



This:



var studentinstance= new student()


...is creating a variable (studentinstance) and assigning a student (singular) instance. The after it is not in any way connected to it, it's just an empty block following the statement which you can and should remove.



I suggest walking through some basic TypeScript tutorials.




¹ In the place it appears (the constructor parameter list), it declares abc as a property of the students instance and also as the first parameter to the constructor (and automatically sets the property from the constructor parameter). So in that sense you might say it creates a property. It doesn't create an object, however.






share|improve this answer
































    0














    : declares a type; it does not create an instance.



    See the documentation.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050229%2fwhat-is-difference-between-keyword-new-and-colon-symbol-while-creating-the-ne%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      public abc:students doesn't create anything.¹ The :students part just assigns a type to abc. It doesn't create an instance of that type, it just says that if abc is going to refer to anything, it has to be of type students.



      This:



      var studentinstance= new student()


      ...is creating a variable (studentinstance) and assigning a student (singular) instance. The after it is not in any way connected to it, it's just an empty block following the statement which you can and should remove.



      I suggest walking through some basic TypeScript tutorials.




      ¹ In the place it appears (the constructor parameter list), it declares abc as a property of the students instance and also as the first parameter to the constructor (and automatically sets the property from the constructor parameter). So in that sense you might say it creates a property. It doesn't create an object, however.






      share|improve this answer





























        0














        public abc:students doesn't create anything.¹ The :students part just assigns a type to abc. It doesn't create an instance of that type, it just says that if abc is going to refer to anything, it has to be of type students.



        This:



        var studentinstance= new student()


        ...is creating a variable (studentinstance) and assigning a student (singular) instance. The after it is not in any way connected to it, it's just an empty block following the statement which you can and should remove.



        I suggest walking through some basic TypeScript tutorials.




        ¹ In the place it appears (the constructor parameter list), it declares abc as a property of the students instance and also as the first parameter to the constructor (and automatically sets the property from the constructor parameter). So in that sense you might say it creates a property. It doesn't create an object, however.






        share|improve this answer



























          0












          0








          0







          public abc:students doesn't create anything.¹ The :students part just assigns a type to abc. It doesn't create an instance of that type, it just says that if abc is going to refer to anything, it has to be of type students.



          This:



          var studentinstance= new student()


          ...is creating a variable (studentinstance) and assigning a student (singular) instance. The after it is not in any way connected to it, it's just an empty block following the statement which you can and should remove.



          I suggest walking through some basic TypeScript tutorials.




          ¹ In the place it appears (the constructor parameter list), it declares abc as a property of the students instance and also as the first parameter to the constructor (and automatically sets the property from the constructor parameter). So in that sense you might say it creates a property. It doesn't create an object, however.






          share|improve this answer















          public abc:students doesn't create anything.¹ The :students part just assigns a type to abc. It doesn't create an instance of that type, it just says that if abc is going to refer to anything, it has to be of type students.



          This:



          var studentinstance= new student()


          ...is creating a variable (studentinstance) and assigning a student (singular) instance. The after it is not in any way connected to it, it's just an empty block following the statement which you can and should remove.



          I suggest walking through some basic TypeScript tutorials.




          ¹ In the place it appears (the constructor parameter list), it declares abc as a property of the students instance and also as the first parameter to the constructor (and automatically sets the property from the constructor parameter). So in that sense you might say it creates a property. It doesn't create an object, however.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 at 18:27

























          answered Mar 7 at 18:10









          T.J. CrowderT.J. Crowder

          697k12312401336




          697k12312401336























              0














              : declares a type; it does not create an instance.



              See the documentation.






              share|improve this answer



























                0














                : declares a type; it does not create an instance.



                See the documentation.






                share|improve this answer

























                  0












                  0








                  0







                  : declares a type; it does not create an instance.



                  See the documentation.






                  share|improve this answer













                  : declares a type; it does not create an instance.



                  See the documentation.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 18:09









                  SLaksSLaks

                  692k13916501770




                  692k13916501770



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050229%2fwhat-is-difference-between-keyword-new-and-colon-symbol-while-creating-the-ne%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                      Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                      Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved