One Language to Rule Them All: TypeScript Loiane Groner @loiane
@loiane loiane.com github.com/loiane youtube.com/loianegroner Software Engineer Loiane Groner
Agenda @loiane ·Pq usar TypeScript? ·Migrando do JavaScript para TypeScript ·TypeScript no Back-end ·TypeScript no Front-end ·Visual Studio Code + TypeScript
Pq TypeScript?
Começando @loiane npm install -g typescript mv main.js main.ts tsc main.ts >_ Também pode usar a achar bugs existentes no seu projeto!
Transpilando @loiane Transpila .ts .js $ tsc > _
Add Config @loiane tsc --init >_
tsconfig.json @loiane { "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es6", "sourceMap": true, "outDir": "./dist", "baseUrl": "./" }, "exclude": ["node_modules"] }
Transpilando @loiane Transpila .js $ tsc > _ config .ts
Fortemente Tipado? @loianehttps://twitter.com/ahejlsberg/status/792762247239995392?s=09
Superset JavaScript opcionalmente tipado que compila para JavaScript "puro" @loiane typescriptlang.org
Demo Iniciando com TypeScript @loiane
Show me the VSCode!
Importante! @loiane ·Todo código JavaScript é um código TypeScript válido · Mesmo que existam erros de compilação no TypeScript!
TypeScript com Node.js
TypeScript para Back-End @loiane $ npm i -D ts-node nodemon typescript tslint >_
Arquivo de Definição @loiane $ npm i --save-dev @types/node @types/express > _ "devDependencies": { "@types/dotenv": "^6.1.1", "@types/express": "^4.16.0", "@types/mongoose": "^5.3.27", "@types/node": "^10.12.18", "@types/passport-jwt": "^3.0.1", "nodemon": "^1.18.9", "ts-node": "^7.0.1", "tslint": "5.12.1", "typescript": "^3.2.4" }, @loiane
Demo TypeScript+ Express + MongoDB @loiane
Show me the VSCode!
Importante! @loiane · Decorators para routes · Decorators para validar objetos · IoC: Inversion of Control (Inversão de Controle) · Inversify · typescript-ioc ·Type ORM
Decorators para routes: OvernightJS! @loiane @Controller('api/attendee') export class AttendeeController { @Get() @Middleware([middleware1, middleware2]) async findAll(req: Request, res: Response) { const records = await Attendee.find(); return res.status(HttpStatus.OK).json(records); } }
Validação de Objetos @loiane import { IsString, Length } from 'class-validator'; export class ArticleDTO { @IsString() @Length(10, 200) article: string; @IsString() description: string; }
Inversão de Controle @loiane import { AutoWired, Inject, Singleton } from 'typescript-ioc'; @Singleton class PersonService { @Inject private personDAO: PersonDAO; } class PersonController { @Inject private personService: PersonService; @Inject creationTime: Date; }
Type ORM @loiane @Entity('article') export class ArticleEntity { @PrimaryGeneratedColumn('uuid') id: string; @CreateDateColumn() created: Date; @UpdateDateColumn() updated: Date; @Column('text') article: string; }
tsconfig.json @loiane { "compilerOptions": { "experimentalDecorators": true, "emitDecoratorMetadata": true } }
Nest.js @loiane
Demo Adicionando libs TypeScript no código @loiane
Show me the VSCode!
TypeScript no Front-end: Angular
Web Moderna @loiane ●Módulos ●Classes ●TypeScript
Desenvolvimento + rápido com ferramentas embutidas @loiane ●CLI ●Router ●HTTP ●Forms ●Animações ●i18n ●Languages Services ●Material & CDK ●E mais!
Demo Angular client @loiane
Show me the VSCode!
@loiane TypeScript + React https://www.typescriptlang.org/samples/index.html
@loiane TypeScript + Vue https://www.typescriptlang.org/samples/index.html
Front + Back + Shared @loiane Client Shared Server
Visual Studio Code
@loiane Depuração
Show me the VSCode!
Recapitulando @loiane ● Adicione Type checking no seu JavaScript ● Use @ts-check para iniciar ● Instale @types para ajudar com auto-complete ● Adicione tipagem onde for necessário (Inferência de tipos) ● + produtividade com bibliotecas e frameworks ● Use TypeScript no lado cliente (front | mobile) ● Visual Studio Code sempre ajuda na produtividade!
Links + Referências @loiane Código Fonte TypeScript Ebook TypeScript Grátis TS Extension Pack Azure Tools Extension Pack TS MERN Nest.js http://bit.ly/typescript-msbuild-2019 http://bit.ly/typescriptlang http://bit.ly/snippet-creator http://bit.ly/ts-extension-pack http://bit.ly/code-azure-pack http://bit.ly/ts-mern https://nestjs.com
Final point A one-line description of it Obrigada!

One Language to Rule Them All: TypeScript