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
The creation of modern web applications has been greatly simplified thanks to frontend development frameworks. These frameworks allow us to build interactive and dynamic interfaces more easily, reducing configuration time and allowing us to focus on what really matters: business logic and user experience. React, developed by Facebook, has positioned itself as one of the most popular and powerful frameworks on the market, especially when combined with TypeScript for more robust development with fewer bugs.
React is a leading framework in frontend development that allows you to create interactive user interfaces efficiently. Combining it with TypeScript gives us additional advantages such as static typing, which reduces errors in development time. Creating a project that integrates both technologies is surprisingly easy thanks to tools like Vite.
To start a React project with TypeScript, we follow these steps:
npm create vite@latest
.The wizard will ask for basic information such as
Once this process is completed, we will have a project framework ready to start developing. The magic of these templates is that all the complex configuration is already done for us, allowing us to concentrate on writing productive code right out of the box.
After creating the project, we will find an organized file structure that includes:
src
: contains the source code of our application.Public
folder: for static filespackage.json
and tsconfig.json
To start our project, we must:
# move to the project foldercd project-name
# install dependenciesnpm install
# start the development servernpm run dev
By executing these commands, our project will be available at a local address (usually http://localhost:5173/)
and we will be able to see a welcome page with a working counter.
One of the peculiarities of working with React and TypeScript is the .tsx
file extension. This special extension combines TypeScript with JSX (JavaScript XML), allowing us to write HTML code directly inside our TypeScript files.
If we explore the App.tsx
file generated in our project, we will see code like this:
import { useState } from 'react'import reactLogo from './assets/react.svg'import './App.css'
function App() { const [counter, setCounter] = useState(0)
return (<div className="App">
<h1>Platzitemplate</h1>
<div className="card">
<button onClick={() => setCounter((counter) => counter + 1)}>
counter: {counter}
</button>
</div>
</div> )}
export default App.
This file shows the JSX syntax, where we can write HTML elements like <div>
, <h1>
and <button>
directly in our TypeScript code. The magic happens when we modify this file: the changes are instantly reflected in the browser thanks to the hot reloading provided by Vite.
The generated project includes configuration files specific to TypeScript:
tsconfig.json
: the main file that references other configuration files.tsconfig.app.json
: application-specific settingstsconfig.node.json
: configuration for Node.js environmentThese files contain the TypeScript compiler options(compilerOptions
) that determine how our code is compiled. The advantage of using a template is that these settings are already optimized to work with React, saving us from having to configure them manually.
The compilation process in a React project with TypeScript is automated thanks to the scripts defined in the package.json
file. When we run npm run dev
, a process chain is triggered which:
The tsc
(TypeScript Compiler) command is responsible for transforming our TypeScript code into JavaScript that the browser can understand. This process is configured in the build
script of the package.json
:
"scripts": { " dev": "vite", " build": "tsc && vite build", " preview": "vite preview"}
The beauty of this system is that everything happens transparently to the developer. We don't need to worry about manually running the compiler or configuring additional tools.
Templates like the one we've created allow us to quickly get started with a React and TypeScript project without having to deal with the initial setup. We can customize this base to our specific needs, adding or removing components and functionality. This approach saves us valuable time that we can spend on developing the unique features of our application instead of setting up the development environment.
Have you tried creating projects with React and TypeScript? What other templates or tools have you found useful to speed up your workflow? Share your experience in the comments.
Contributions 3
Questions 0
Want to see more contributions, questions and answers from the community?