Typescript

Contactar con el profesor

Documentación oficial

sudo create-react-app miproyectotypescript -typescript
Tipado básico
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { number } from 'prop-types';

interface Author {
  id: number;
  name: string;
  age: number;
}

interface Book {
  id: number;
  title: string;
  price: number;
  author: Author;
}


const author : Author = {
  id:0,
  name: "Pablo Monteserín",
  age: 27
}

const books: Book[] = [
  {
    id:0,
    title: "Monteserín lo ha vuelto a hacer",
    price: 21,
    author: author
  },
  {
    id:1,
    title: "Monteserín se va a la montaña",
    price: 19,
    author: author
  }
]

interface NumberAndString {
  number: number;
  string: string;
}
const getNumberAndString = (number:number, string:string):NumberAndString => {

  const NumberAndString ={
    number: 3,
    string: "monteserin"
  }  

  return NumberAndString;
}
const App: React.FC = () => {
  const myNumberAndString = getNumberAndString(3, "hola");


  return (
    
    <div className="App">
      {
        books.map(obj => <p>{obj.title}</p>)
      }
      
       <p>{myNumberAndString.string}</p>
      
    </div>
  );
}

export default App;
← Styleguidist
Empaquetar con NPM →

Aviso Legal | Política de privacidad