Skip to content

Learn TypeScript from scratch and enhance your development skills. This course will teach you how to write safer, scalable code by leveraging the power of a typed language that seamlessly integrates with JavaScript. Perfect for developers looking to build robust, modern applications.

Notifications You must be signed in to change notification settings

IngSystemCix/typescript_course

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Guía Completa de TypeScript (TSC)

Autor: Juan Bladimir Romero Collazos

Introducción

TypeScript es un lenguaje de programación desarrollado y mantenido por Microsoft. Es un superconjunto de JavaScript que añade tipos estáticos opcionales.

Instalación

Para instalar TypeScript, puedes usar npm:

npm install -g typescript

Compilación

Para compilar archivos TypeScript (.ts), usa el comando tsc:

tsc archivo.ts

Configuración

Puedes crear un archivo tsconfig.json para configurar el compilador TypeScript:

tsc --init
"include": [
    "ts/**/*"   // Incluye todos los archivos .ts en la carpeta 'ts'
]

Compile

Debes ejecutar el siguiente comando

tsc

Tipos Básicos

Boolean

let isDone: boolean = false;

Number

let decimal: number = 6;

String

let color: string = "blue";

Array

let list: number[] = [1, 2, 3];

Tuple

let x: [string, number];
x = ["hello", 10];

Enum

enum Color {Red, Green, Blue}
let c: Color = Color.Green;

Any

let notSure: any = 4;
notSure = "maybe a string instead";

Void

function warnUser(): void {
    console.log("This is my warning message");
}

Interfaces

interface Person {
    firstName: string;
    lastName: string;
}

function greeter(person: Person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}

let user = { firstName: "Jane", lastName: "User" };
console.log(greeter(user));

Clases

class Animal {
    private name: string;

    constructor(name: string) {
        this.name = name;
    }

    public move(distanceInMeters: number): void {
        console.log(`${this.name} moved ${distanceInMeters}m.`);
    }
}

let dog = new Animal("Dog");
dog.move(10);

Módulos

// math.ts
export function add(x: number, y: number): number {
    return x + y;
}

// app.ts
import { add } from "./math";
console.log(add(2, 3));

Conclusión

TypeScript es una poderosa herramienta para desarrollar aplicaciones JavaScript robustas y mantenibles. Esta guía cubre los conceptos básicos, pero hay mucho más por explorar.

About

Learn TypeScript from scratch and enhance your development skills. This course will teach you how to write safer, scalable code by leveraging the power of a typed language that seamlessly integrates with JavaScript. Perfect for developers looking to build robust, modern applications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published