Fundamentos de TypeScript
驴Qu茅 es TypeScript y por qu茅 usarlo?
Instalaci贸n de Node.js y TypeScript CLI, configuraci贸n de tsconfig.json
Tipos primitivos: string, number, boolean, null, undefined de Typescript
Tipos especiales: any, unknown, never, void de TypeScript
Arrays, Tuplas, Enums en TypeScript
Funciones e Interfaces
Declaraci贸n de funciones, tipado de par谩metros y valores de retorno
Par谩metros opcionales, valores por defecto y sobrecarga de funciones
Creaci贸n y uso de interfaces de TypeScript
Propiedades opcionales, readonly, extensi贸n de interfaces en TypeScript
Clases y Programaci贸n Orientada a Objetos
Creaci贸n de clases y constructores En TypeScript
Modificadores de acceso (public, private, protected) en Typescript
Uso de extends, sobreescritura de m茅todos en TypeScript
Introducci贸n a Gen茅ricos en Typescript
Restricciones con extends, gen茅ricos en interfaces
M贸dulos y Proyectos
Importaci贸n y exportaci贸n de m贸dulos en TypeScript
Agregando mi archivo de Typescript a un sitio web
Configuraci贸n de un proyecto Web con TypeScript
Selecci贸n de elementos, eventos, tipado en querySelector en TypeScript
Crear un proyecto de React.js con Typescript
Crea un proyecto con Angular y Typescript
Crea una API con Typescript y Express.js
Conceptos Avanzados
Introducci贸n a types en TypeScript
Implementaci贸n de Decoradores de TypeScript
Async/await en Typescript
Pruebas unitarias con Jest y TypeScript
Principios SOLID, c贸digo limpio, patrones de dise帽o en Typescript
You don't have access to this class
Keep learning! Join and start boosting your career
TypeScript programming offers a robust and secure experience for developers looking to avoid common JavaScript errors. This programming language, which extends JavaScript with static typing, allows you to create more maintainable and scalable applications. Let's explore the basics to get started programming with TypeScript.
To start programming in TypeScript, the first thing we need to do is to create our classic "Hello World". This exercise will allow us to understand the basic process of compiling and executing TypeScript code.
First, we create a new file with extension .ts
:
console.log("Hello world");
Once we have written our code, we need to compile it to convert it to JavaScript, since TypeScript does not run directly in browsers or in Node.js:
tsc
command followed by the name of your file:tsc main.ts
This command will generate an equivalent JavaScript file(main.js
). To run it, we simply use Node.js:
node main.js
And we will see in the terminal our "Hello world" message. This compilation process is fundamental in TypeScript, as it transforms our code with types to pure JavaScript that can be interpreted by any environment.
The main feature of TypeScript is the type system. Unlike JavaScript, where variables can change type during execution, TypeScript allows us to explicitly define what type of data each variable will contain.
Let's look at some basic examples:
// String variablelet name: string = "min";
// Number variablelet age: number = 39;
// Boolean variablelet developer: boolean = true;
// Variable that can be undefined or stringlet month: undefined | string;
console.log(`Hello ${name}`);console.log(month); // Result: undefined
month = "january";console.log("updated month:", month); // Result: january
In the above example, we can see how we declare variables with different types:
name
can only contain textage
can only contain numbersdeveloper
can only be true or falsemonth
can be a text string or be undefinedTypeScript offers different ways to work with text strings, similar to JavaScript. We can concatenate variables using the +
operator or use template literals (string templates) with backticks (``).
let name: string = "min";
// Option 1: Traditional concatenationconsole.log("Hello " + name);
// Option 2: Template literals (recommended)console.log(`Hello ${name}`);
Both options produce the same result, but template literals are more readable when we work with long strings or need to insert multiple variables.
TypeScript includes several basic data types that help us to clearly define the structure of our code:
We can also create union types by combining several types with the |
operator:
// This variable can be undefined or stringlet month: undefined | string;
console.log("initial month", month); // undefined
month = "January";console.log("updated month", month); // January.
In this example, month
can contain text or be undefined. This is useful when a variable can have different types of values depending on the context.
The best way to learn TypeScript is to experiment with different types of variables and observe how they behave. We recommend:
console.log()
to visualize the valuesThe TypeScript development process always includes these steps: write typed code, compile to JavaScript and execute the result. This cycle will help you become familiar with the language and its features.
Constant practice with these basic concepts will give you a solid foundation to move on to more complex TypeScript features. We encourage you to experiment with the examples shown and create your own variations to consolidate your learning. What other data types would you like to explore in TypeScript? Share your experiences in the comments!
Contributions 9
Questions 0
Want to see more contributions, questions and answers from the community?