├── actions.js ├── actions.ts ├── destruc.ts ├── enums.js ├── enums.ts ├── main.js ├── main.ts ├── oo.js └── tsconfig.json /actions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var UsuariosActionTypes; 3 | (function (UsuariosActionTypes) { 4 | UsuariosActionTypes["LOAD_REQUEST"] = "[Usuarios] Load Request"; 5 | UsuariosActionTypes["LOAD_SUCCESS"] = "[Usuarios] Load Success"; 6 | })(UsuariosActionTypes || (UsuariosActionTypes = {})); 7 | -------------------------------------------------------------------------------- /actions.ts: -------------------------------------------------------------------------------- 1 | enum UsuariosActionTypes { 2 | LOAD_REQUEST = '[Usuarios] Load Request', 3 | LOAD_SUCCESS = '[Usuarios] Load Success' 4 | } 5 | 6 | interface Usuario { 7 | nome: string; 8 | } 9 | 10 | type UsuarioActions = 11 | | { type: UsuariosActionTypes.LOAD_REQUEST; } 12 | | { type: UsuariosActionTypes.LOAD_SUCCESS; payload: Usuario[] }; 13 | 14 | -------------------------------------------------------------------------------- /destruc.ts: -------------------------------------------------------------------------------- 1 | interface Livro { 2 | id: number; 3 | titulo: string; 4 | autor: string; 5 | } 6 | 7 | function getLivros(): Livro[] { 8 | return [ 9 | {id: 1, titulo: 'JavaScript Data Structures Algorithms', autor: 'Loiane Groner'}, 10 | {id: 2, titulo: 'Mastering ExtJS', autor: 'Loiane Groner'}, 11 | {id: 3, titulo: 'ExtJS First Look', autor: 'Loiane Groner'} 12 | ]; 13 | } 14 | 15 | function imprimirLivro({titulo: livro, autor: autora}: Livro) { 16 | console.log(`${livro} foi escrito por ${autora}`); 17 | } 18 | 19 | function log([livro1, livro2]: Livro[]) { 20 | imprimirLivro(livro1); 21 | imprimirLivro(livro2); 22 | } 23 | 24 | log(getLivros()); -------------------------------------------------------------------------------- /enums.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function calcularArea(figura) { 3 | switch (figura.tipo) { 4 | case 'circulo': return Math.PI * Math.pow(figura.raio, 2); 5 | case 'retangulo': return figura.a * figura.l; 6 | case 'quadrado': Math.pow(figura.l, 2); 7 | } 8 | throw new Error('Figura inválida'); 9 | } 10 | var circulo = { tipo: 'circulo', raio: 2 }; 11 | calcularArea(circulo); 12 | -------------------------------------------------------------------------------- /enums.ts: -------------------------------------------------------------------------------- 1 | type Figura = 2 | {tipo: 'circulo', raio: number} | 3 | {tipo: 'retangulo', a: number, l: number} | 4 | {tipo: 'quadrado', l: number}; 5 | 6 | function calcularArea(figura: Figura): number { 7 | switch(figura.tipo){ 8 | case 'circulo': return Math.PI * figura.raio ** 2; 9 | case 'retangulo': return figura.a * figura.l; 10 | case 'quadrado': figura.l ** 2; 11 | } 12 | throw new Error('Figura inválida'); 13 | } 14 | 15 | const circulo: Figura = {tipo: 'circulo', raio: 2}; 16 | calcularArea(circulo); 17 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function ordernarNome(a) { 3 | var result = a.slice(0); 4 | result.sort(function (x, y) { 5 | return x.nome.localeCompare(y.nome); 6 | }); 7 | return result; 8 | } 9 | ordernarNome([]); 10 | var OlaMundo = /** @class */ (function () { 11 | //nome: string; 12 | function OlaMundo(nome) { 13 | this.nome = nome; 14 | } 15 | OlaMundo.prototype.ola = function () { 16 | console.log("Ol\u00E1 " + this.nome); 17 | }; 18 | return OlaMundo; 19 | }()); 20 | //Faça 21 | var varString = 'BrazilJS'; 22 | //NÀO FAÇA 23 | var string2 = 'BrazilJS'; 24 | var maria = { nome: 'Maria', idade: 20 }; 25 | var joao = { nome: 'João', idade: 21, telefone: '34533545' }; 26 | ordernarNome([maria, joao]); 27 | function contarLinhas(texto) { 28 | var count = 0; 29 | if (texto) { 30 | for (var _i = 0, texto_1 = texto; _i < texto_1.length; _i++) { 31 | var linha = texto_1[_i]; 32 | if (linha && linha.length !== 0) { 33 | count = count + 1; 34 | } 35 | } 36 | } 37 | return count; 38 | } 39 | var a = contarLinhas(['um', 'dois', '', 'tres']); 40 | var b = contarLinhas(['ola', null, 'mundo']); 41 | var c = contarLinhas(); 42 | -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | interface Pessoa { 2 | nome: string; 3 | idade: number; 4 | } 5 | 6 | interface PessoaTel extends Pessoa { 7 | telefone: string; 8 | } 9 | 10 | function ordernarNome(a: Pessoa[]) { 11 | var result = a.slice(0); 12 | result.sort(function(x, y) { 13 | return x.nome.localeCompare(y.nome); 14 | }); 15 | return result; 16 | } 17 | 18 | ordernarNome([]); 19 | 20 | class OlaMundo { 21 | //nome: string; 22 | constructor(public nome: string) {} 23 | ola() { 24 | console.log(`Olá ${this.nome}`); 25 | } 26 | } 27 | 28 | //Faça 29 | let varString = 'BrazilJS'; 30 | 31 | //NÀO FAÇA 32 | let string2: string = 'BrazilJS'; 33 | 34 | let maria: Pessoa = { nome: 'Maria', idade: 20 }; 35 | let joao: PessoaTel = { nome: 'João', idade: 21, telefone: '34533545' }; 36 | 37 | ordernarNome([maria, joao]); 38 | 39 | function contarLinhas(texto?: (string | null)[]): number { 40 | let count = 0; 41 | if (texto) { 42 | for (const linha of texto) { 43 | if (linha && linha.length !== 0) { 44 | count = count + 1; 45 | } 46 | } 47 | } 48 | return count; 49 | } 50 | 51 | let a = contarLinhas(['um', 'dois', '', 'tres']); 52 | let b = contarLinhas(['ola', null, 'mundo']); 53 | let c = contarLinhas(); 54 | -------------------------------------------------------------------------------- /oo.js: -------------------------------------------------------------------------------- 1 | export class Cachorro extends Animal { 2 | /** 3 | * @param {string} nome 4 | * @param {number} idade 5 | */ 6 | constructor(nome, idade) { 7 | super(); 8 | this.nome = nome; 9 | this.idade = idade; 10 | } 11 | 12 | late() { 13 | console.log(`${this._nome} late: AU AU!`); 14 | } 15 | } 16 | let pet = new Cachorro(8, 'Jake'); 17 | 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ 5 | "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 6 | // "lib": [], /* Specify library files to be included in the compilation: */ 7 | // "allowJs": true, /* Allow javascript files to be compiled. */ 8 | // "checkJs": true, /* Report errors in .js files. */ 9 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 10 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 11 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 12 | // "outFile": "./", /* Concatenate and emit output to single file. */ 13 | // "outDir": "./", /* Redirect output structure to the directory. */ 14 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 15 | // "removeComments": true, /* Do not emit comments to output. */ 16 | // "noEmit": true, /* Do not emit outputs. */ 17 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 18 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 19 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 20 | 21 | /* Strict Type-Checking Options */ 22 | "strict": true /* Enable all strict type-checking options. */ 23 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 24 | //"strictNullChecks": true, /* Enable strict null checks. */ 25 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 26 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 27 | 28 | /* Additional Checks */ 29 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 30 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 31 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 32 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 33 | 34 | /* Module Resolution Options */ 35 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 36 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 37 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 38 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 39 | // "typeRoots": [], /* List of folders to include type definitions from. */ 40 | // "types": [], /* Type declaration files to be included in compilation. */ 41 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 42 | 43 | /* Source Map Options */ 44 | // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 45 | // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ 46 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 47 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 48 | 49 | /* Experimental Options */ 50 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 51 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 52 | } 53 | } --------------------------------------------------------------------------------