EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Login
Home Software Development Software Development Tutorials TypeScript Tutorial TypeScript npm

TypeScript npm

Updated April 10, 2023

TypeScript npm

Introduction to TypeScript npm

The following article provides an outline for TypeScript npm. TypeScript is a language used for application scale JavaScript. Microsoft develops and maintains TypeScript. TypeScript adds more features but also follows JavaScript on the basis of its syntax. Basically, TypeScript is a superset of JavaScript. Optional types are added to JavaScript using TypeScript which supports various tools for creating large-scale JavaScript applications irrespective of the browser, host or operating system. Basically, TypeScript is a language that compiles codes to readable codes of JavaScript.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax to install tsc or using npm in TypeScript:

npm install -g typescript

Working of npm in TypeScript

For installing TypeScript, there are two ways:

  • js package manager also called as npm is used for installing TypeScript.
  • TypeScript plug-in can also be used in the Integrated Development Environment.

TypeScript is a language which starts using JavaScript and also ends with JavaScript. The basic building blocks of JavaScript is adopted by TypeScript. So, a person only needs to understand JavaScript for using TypeScript. After writing the complete TypeScript code and executing it, the TypeScript code gets converted into JavaScript code which would be equivalent to the original TypeScript code and the resultant is used for final execution.

Any executable .js file can be converted or renamed into .ts file to get compiled along with the other TypeScript files. String values in TypeScript are used with keyword “string” and numeric values are used with keyword “number” in TypeScript. These keywords are used in several examples below.

Examples of TypeScript npm

Given below are the examples mentioned:

If you have saved the file of the below codes as Rahul.ts, so to compile TypeScript code you can run the following command on the command line: tsc Rahul.ts.

By doing this a JavaScript file will be generated as Rahul.js and to run this javascript file use the following command on the command line: Node Rahul.js.

Example #1

Code:

class TrainingProvider {
Typescript():void {
console.log(
"**EDUCBA**"
)
}
}
var obj = new TrainingProvider();
obj.Typescript();

Output:

TypeScript npm 1

Example #2

Code:

var year: number = 2021;
var us: string = "EDUCBA";
var course1: string = "TypeScript";
var price1: number = 232323;
var course2: string = "React Native";
var price2: number = 212121;
var course3: string = "React";
var price3: number = 191919;
var course4: string = "Data Science";
var price4: number = 252525;
var course5: string = "Finance";
var price5: number = 171717;
var course6: string = "Swift";
var price6: number = 151515;
var Contact_us: number = 9876543210;
console.log(year + " journey " + us + course1 + price1 + course2 + price2 + course3 + price3 + course4 + price4 + course5 + price5 + course6 + price6 + "You can" + "Call us on" + Contact_us)

Output:

TypeScript npm 2

Example #3

Code:

function Textual(
M: string
, N: string) {
return M + N;
}
var Texting: string = Textual(
"Great"
, "Training")
console.log(' We are : ' + Texting + "providers :P");
function Numeric(
S: number
, T: number) {
return S + T;
}
var Numbernew: number = Numeric(
14092019
, 14092021)
console.log(' Added numbers concluded to : ' + Numbernew );

Output:

Added numbers concluded

Example #4

Code:

function Numeric(
M: number
, N: number) {
return M * N;
}
var Numbernew1: number = Numeric(
14092019
, 14092021)
console.log(' Multiplied numbers concluded to : ' + Numbernew1 );
function Numeric1(
S: number
, T: number) {
return S + T;
}
var Numbernew: number = Numeric1(
14092019
, 14092021)
console.log(' Added numbers concluded to : ' + Numbernew );
function Numeric2(
Q: number
, R: number) {
return Q - R;
}
var Numbernew2: number = Numeric2(
14092019
, 14092021)
console.log(' Subtracted numbers concluded to : ' + Numbernew2 );

Output:

Multiplied numbers

Conclusion

On the basis of the above article, we can understand the concept of TypeScript and how it is used to simplify the complexity of JavaScript for large applications. This article explains TypeScript using different examples and the working of TypeScript with node.js package manager commonly known as npm. These examples would help the beginners to understand and work on TypeScript.

Recommended Articles

This is a guide to TypeScript npm. Here we discuss the introduction, working of npm in TypeScript and examples respectively. You may also have a look at the following articles to learn more –

  1. TypeScript Functions
  2. TypeScript Operators
  3. TypeScript Versions
  4. What is TypeScript?
ADVERTISEMENT
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
Financial Analyst Masters Training Program
2000+ Hours of HD Videos
43 Learning Paths
550+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Data Science Bundle
2000+ Hour of HD Videos
80 Learning Paths
400+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Software Development Bundle
5000+ Hours of HD Videos
149 Learning Paths
1050+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW