📘
NavDoc by Bash School
GithubContact
📘
NavDoc by Bash School
  • 🎓Introduction
  • 🐢Getting Started
  • ⚡Changelog
  • 👨‍🚀Maintainers
  • 🛣️Roadmap
  • Fundamentals
    • The Internet
      • Introduction
      • What is a URL
      • What is a port
      • The DNS protocol
      • The TCP protocol
      • The UDP protocol
      • The Web
      • The HTTP protocol
      • Hyperlinks
      • What is a Web browser
      • What is a Web server
    • HTML
      • Your first HTML page
      • Text tags
      • Attributes
      • Links
      • Images
      • Lists
      • Head Tags
      • Container tags
    • CSS
      • Introduction
      • Colors
      • selectors
      • Cascade
      • Specificity
      • Units
      • Advanced selectors
      • Typography
      • The box model
      • The display property
      • Responsive design
  • JavaScript
    • Basics
      • Introduction
      • Literals , Identifiers, Variables
      • Comments
      • The difference between let, const and var
      • Types
      • Operators and expressions
      • Arithmetic operators
      • The assignment operator
      • Operators precedence
      • Strings
      • Numbers
      • Semicolons, white space and sensitivity
      • Arrays
      • Conditionals
      • Loops
      • Functions
      • Objects
      • Arrays + functions
      • OOPS
      • Asynchronous
      • Scope, hoisting, event loop
      • ES Modules
      • Errors and exceptions
      • Built-in objects
        • The global object
        • Object properties
        • Number
        • String
        • Math
        • JSON
        • Date
        • Intl
        • Set and Map
      • More operators
    • Nodejs
      • Getting Started
      • Installation
      • Hello World in Node
      • Modules
      • Packages
      • File Handling
      • HTTP Request
      • Processing Files
      • HTTP
    • Express.js
      • Getting Started
      • Middleware
      • Serve Static Assets
      • How to Send Files to the Client
      • Sessions
      • Validate Input
      • Sanitizing Data
      • Forms
      • File Uploads
    • React
      • Setting up a React project with Vite
      • React Components
      • Introduction to JSX
      • Using JSX to compose UI
      • The difference between JSX and HTML
      • Embedding JavaScript in JSX
      • Handling user events
      • Managing state
      • Component props
      • Data flow
      • Lifecycle events
      • Managing forms in React
      • Install the React Developer Tools
      • Installing Tailwind CSS in a React app
      • Build a counter in React
    • TypeScript
      • Key Benefits
      • Types of Languages
      • The Need for TypeScript
      • What is TypeScript?
      • The tsc Compiler
      • Basic Types in TypeScript
      • tsconfig
      • Interfaces
      • Types
      • Arrays in TypeScript
      • Enums
      • Exporting and importing
    • MongoDB
      • SQL vs. NoSQL Databases
      • Installing MongoDB
      • MongoDB Databases and Collections
      • Working with Documents
      • MongoDB Operators
      • Sorting, Indexing & Searching
      • Built-in Methods
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. JavaScript
  2. TypeScript

What is TypeScript?

PreviousThe Need for TypeScriptNextThe tsc Compiler

Last updated 12 months ago

Was this helpful?

TypeScript is a programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, meaning it includes all JavaScript features and adds additional capabilities, most notably optional static typing.

Key Features of TypeScript

  • Optional Static Typing: Unlike JavaScript, TypeScript allows you to define types for variables, function parameters, and return values, enhancing code quality and reducing bugs.

  • Superset of JavaScript: TypeScript builds on JavaScript, meaning any valid JavaScript code is also valid TypeScript code. This makes transitioning to TypeScript straightforward.

How Does TypeScript Code Run?

TypeScript code itself does not run directly in the browser or any JavaScript runtime environment like Node.js. Instead, TypeScript code is compiled into plain JavaScript code, which can then be executed by the browser or Node.js.

  • JavaScript as the Runtime Language: The browser and Node.js understand only JavaScript. Thus, TypeScript must be converted (compiled) into JavaScript before it can run.

  • Compilation Process: During the compilation process, TypeScript performs type checking. If there are type errors, the compilation fails, and the JavaScript code is not generated. This ensures that only type-safe code is converted into JavaScript.

TypeScript Compiler

The official TypeScript compiler is tsc. This tool is used to compile TypeScript code into JavaScript.

How to Use tsc:

  1. Install TypeScript: Install TypeScript globally using npm.

    npm install -g typescript
  2. Compile TypeScript: Use the tsc command to compile your TypeScript file.

    tsc yourfile.ts

Other Compilers/Transpilers

Apart from tsc, there are several other popular tools to compile or transpile TypeScript into JavaScript:

  • esbuild: Known for its speed, esbuild is a modern build tool that supports TypeScript and offers very fast compilation.

  • swc: Another fast compiler written in Rust, swc provides excellent performance for large codebases and supports TypeScript.

By using these tools, developers can seamlessly integrate TypeScript into their development workflow, ensuring that the code is robust, maintainable, and free from type-related errors.