@ltciro
Co-organizadora en @pionerasdev Desarrollo en Ruby, Node, Arduino para IoT
let nodeIs: string = "Genial" //string
nodeIs = true // error
let nodeIs = "Genial" //string
nodeIs = true // boolean
To Type or Not to Type: Quantifying Detectable Bugs in JavaScript
Herramientas.
import { Request, Response } from "express";
interface SuperHeroRequest extends Request {
superheroName: string;
}
//And then use it in a route:
app.router.get("/heroes", (req: SuperHeroRequest, res: Response) => {
if (req.superheroName) {
res.send("I'm Batman")
}
});
npm install --save-dev typescript
npm install --save-dev @types/node
{
"compilerOptions": {
"allowJs": true,
"target": "es2017",
"module": "commonjs",
"outDir": "dist"
},
"include": [
"main/**/*.ts"
],
"exclude": [
"node_modules"
],
"typeRoots": [
"./node_modules/@types"
]
}
$ npm run prod
"scripts": {
"compile": "node_modules/.bin/tsc",
"prod": "npm run compile && node ./dist/main.js"
},
npm install --save-dev ts-node
npm install --save-dev nodemon
npm install --save-dev cpy-cli
$ npm run prod
o
$ npm start
"scripts": {
"compile": "node_modules/.bin/tsc",
"copyfiles": "cpy '**/*.json' '../dist/' --cwd=main --parents",
"prod": "npm run compile && npm run copyfiles && node ./dist/main.js",
"start": "npm run build:live",
"test": "mocha -r ts-node/register test/*.ts test/**/*.ts test/**/**/*.ts
test/**/**/**/*.ts|| true",
"build:live": "nodemon --exec ts-node -- ./main/main.ts"
}
$ npm i -g @nestjs/cli
$ nest new project-name