“Cómo definir tipos en TypeScript” Código de respuesta

Integer de mecanografiado

// There is no int type, use number
const myInt: number = 17;
const myDecimal: number = 17.5;
Arrogant Ape

tipos de variables mecanografiados

let name: string; // stores text
let age: number; // stores numbers
let isMale: boolean; // stores a true or false values
let typeAny: any; // stores any type of value
let typeNull: null = null; // can only store a null value
let typeUndefined: undefined = undefined; // can only store undefined value

// these are the basic types of variables in TypeScript
// and of course you can change let to const
ST111

Cómo definir tipos en TypeScript

type Person = {
  name: string;
  age: number;
};

const person: Person {
	named: 'Rex'
  	age: 23
}
 
function greet(person: Person) {
  return "Hello " + person.name;
}
REX OMIV

Cómo definir tipos en TypeScript

interface Person {
  name: string;
  age: number;
}

const person:Person {
	name: "Rex",
    age: 20
}
 
function greet(person: Person) {
  return "Hello " + person.name;
}
REX OMIV

Respuestas similares a “Cómo definir tipos en TypeScript”

Preguntas similares a “Cómo definir tipos en TypeScript”

Más respuestas relacionadas con “Cómo definir tipos en TypeScript” en TypeScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código