General and Web Programming Fundamentals
  • Introduction
  • Program creation and design
    • Program design
      • Algorithms
      • Pseudocode
    • Programming conventions
    • Writing programs
      • Source code editors
      • Integrated Development Environments
      • Code repositories/Version control
      • Compilers/Interpreters
  • Programming Fundamentals
    • Operators
      • Arithmetic
      • Logical
      • Assignment
    • Constants and Variables
    • Datatypes
      • Primitive Datatypes
        • Character
        • Integer
        • Boolean
        • Floating point
        • Nothing (Null)
      • Composite Datatypes
        • Arrays
        • Strings
        • Classes
        • Structs
      • Literals
    • Data structures
      • Lists
      • Queues
      • Stacks
      • Map/dictionary
      • Trees
      • Graphs
    • Control structures
      • Selection (Conditional)
        • If/Else
        • Ternary
        • Switch
      • Iteration (Loops)
        • For loops
        • While loops
        • Do-While loops
        • For-Each loops
    • Functions
      • Parameters and arguments
      • Lambda expressions
      • Higher Order Functions
    • Space and Time
    • Scope
    • Standard libraries
  • Programming Paradigms
    • Procedural (Imperative) Programming
    • Object-oriented programming
    • Functional Programming
    • Declarative Programming
    • Event Driven programming
  • Programming Languages
    • Short history of programming
    • Low-level programming languages
    • High-level programming languages
  • Web Development
    • What is the web?
      • Web browsers (clients)
      • Webservers (serving web pages)
      • W3C
    • Markup languages
      • HTML
        • HTML Tags
      • Cascading Style Sheets (CSS)
        • CSS Properties
      • XML
      • Markdown
    • Scripting Languages
      • JavaScript
      • TypeScript
    • JSON
    • JavaScript Frameworks
  • Acknowledgements
    • About the author(s)
  • License
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Web Development
  2. Scripting Languages

TypeScript

What is TypeScript?

TypeScript is a superset of JavaScript developed by Microsoft that adds static types to the language. It is designed for the development of large applications and transcompiles to JavaScript.

TypeScript vs. JavaScript

  • Static Typing: TypeScript introduces static typing, allowing developers to define types for variables, function parameters, and return values. JavaScript is dynamically typed.

  • Class Features: TypeScript supports modern JavaScript features as well as additional features such as enums and interfaces, providing more tools to catch errors at compile time.

  • Tool Support: TypeScript offers enhanced autocompletion, navigation, and refactoring services in editors, thanks to its type information.

  • Compatibility: TypeScript code is compiled down to JavaScript, making it compatible with any JavaScript environment.

  • Learning Curve: JavaScript developers may face a learning curve with TypeScript's typing system and additional features, but the core language remains familiar.

Current Uses of TypeScript

  • Web Development: Widely used in front-end and back-end development for structuring large and complex web applications.

  • Frameworks and Libraries: Many popular frameworks and libraries like Angular, React (with TypeScript definitions), and Vue.js support or encourage using TypeScript for development.

  • Enterprise-Level Applications: Its static typing and object-oriented features make TypeScript an ideal choice for enterprise-level applications that require maintainability and scalability.

// Example of integrating TypeScript with a webpage

// Define an interface for a user
interface User {
  name: string;
  age: number;
}

// A function that takes a User object and returns a greeting message
function greetUser(user: User): string {
  return `Hello, ${user.name}! You are ${user.age} years old.`;
}

// Creating a User object
const user: User = {
  name: "John Doe",
  age: 30
};

// Using the function and displaying the greeting in the webpage
document.body.innerHTML = greetUser(user);
PreviousJavaScriptNextJSON

Last updated 1 year ago

Was this helpful?