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

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

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

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

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

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 2823

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T08:59:08+00:00 2024-11-26T08:59:08+00:00

A Brand New World: An Intro to TypeScript

  • 61k

TypeScript is a great addition to your toolkit if you’re a budding full-stack developer. It is popular amongst programmers today because it enhances JavaScript code making it more productive and less error-prone.

One of the main reasons for this increased productivity is the fact that TypeScript is a 'superset' of JavaScript: every piece of code you've ever written (or ever will write) in JavaScript is also TypeScript code.

TypeScript was created in 2012 by Microsoft, to help overcome the issues developers had when scaling up applications with JavaScript. The language’s popularity has slowly grown over the years with each successive, and open-sourced version, thanks to the broadening of its support for non-Microsoft branded environments and technologies.

Benefits & Drawbacks

At some point in your code journey, you’ll forget what every variable is supposed to be; it’s natural and everyone does it, no matter how skilled they are at coding.

Over at TypeScript's official site, they offer the following information:

“TypeScript provides static typing through type annotations to enable type checking at compile time. This is optional and can be ignored to use the regular dynamic typing of JavaScript.”

In other words, TypeScript notates (this is called type annotation) your data type choices while you write code, and then actively checks throughout the life of the program whether or not you’ve stuck to the data types you defined earlier.

This early detection system helps you and anyone you may be collaborating with. The downside to this is you will spend more time writing your code.

It also makes the environment setup stage a longer process: you must interact with the tsconfig.json file to make your overall experience run smoothly. I will say, this does provide an opportunity for you to create a more customized experience.

Another concern is that TypeScript can’t run on a browser. The language must first be compiled, either by its in-house compiler, tsc, or another transpilation program such as Babel. A benefit of this translation process is that even though TypeScript identifies type errors, once the code has been compiled, those errors remain readable only in .ts files.

Now that we’ve got a conceptual understanding down, I’ve provided a short coded example of what TypeScript's type annotation looks and acts like. I highly recommend the TypeScript Sandbox if you’re interested in exploring the code yourself.

A Quick Visual Example

 let message: string = 'Good morning, good evening, & good night'; 
Enter fullscreen mode Exit fullscreen mode

After declaring the ‘message’ variable, I added a colon and the name of the data type.

Technically, you don’t have to set an annotation: TypeScript does this for you in the background, but while learning, this might just be the helpful visual reminder you never knew you needed.

Here's what happens when I try to reassign message to a different data type:

console.log(message = 2);   // prints "Type 'number' is not assignable to type 'string' 
Enter fullscreen mode Exit fullscreen mode

Variables bound to arrays are written with a colon, followed by a one-word description of the element types, and a pair of brackets.

let authorsArray: string[] = ['Zadie Smith', 'Thomas Hardy'];  let anyTypesArray: any[] = ['eight', 8, true]; 
Enter fullscreen mode Exit fullscreen mode

This article answers a few journalistic questions: the why, how, what and when of the TypeScript language. It was written to give you a quick introduction, but I hope it has piqued your curiosity, allowing you to explore and appreciate the many different and interesting aspects of TypeScript-based programming. Thanks for reading!

Sources:

Typescript
Wikipedia
Photo by Pixabay

beginnersjavascripttypescriptwebdev
  • 0 0 Answers
  • 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

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

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

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

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.