├── .gitignore ├── main.ts ├── .editorconfig ├── dist ├── main.js ├── interfaces.js ├── classes.js ├── functions.js └── basic_types.js ├── package.json ├── README.md ├── functions.ts ├── classes.ts ├── basic_types.ts ├── interfaces.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | *.log 3 | -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | function multiply(a: number, b: number): number { 2 | return a * b; 3 | } 4 | 5 | console.log(multiply(2, 15)); 6 | 7 | export { multiply } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | end_of_line = lf -------------------------------------------------------------------------------- /dist/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.multiply = void 0; 4 | function multiply(a, b) { 5 | return a * b; 6 | } 7 | exports.multiply = multiply; 8 | console.log(multiply(2, 15)); 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "intro-typescript", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "typescript": "^4.7.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Curso Introdução ao TypeScript 2 | 3 | TypeScript é uma linguagem de programação de código aberto desenvolvida pela Microsoft. É um superconjunto sintático estrito de JavaScript e adiciona tipagem estática opcional à linguagem. 4 | 5 | - :movie_camera: [Acesse o Curso](https://academy.especializati.com.br/curso/introducao-ao-typescript). 6 | 7 | 8 | Links Úteis: 9 | 10 | - :tada: [Saiba Mais](https://linktr.ee/especializati) 11 | -------------------------------------------------------------------------------- /dist/interfaces.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const getUser = (user) => { 3 | return `${user.firstName} ${user.lastName}, age: ${user.age}`; 4 | }; 5 | // let user = { 6 | // firstName: 'Carlos', 7 | // lastName: 'Ferreira', 8 | // age: 30 9 | // } 10 | // console.log(getUser(user)) 11 | class Person { 12 | constructor(firstN, lastN, ageU) { 13 | this.firstName = firstN; 14 | this.lastName = lastN; 15 | this.age = ageU; 16 | } 17 | getFullName() { 18 | return `${this.firstName} ${this.lastName}`; 19 | } 20 | } 21 | let person = new Person('Carlos', 'Ferreira', 30); 22 | console.log(getUser(person)); 23 | -------------------------------------------------------------------------------- /dist/classes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | class User { 3 | constructor(firstName, lastName, age) { 4 | this.firstName = firstName; 5 | this.lastName = lastName; 6 | this.age = age; 7 | // this.validate(); 8 | } 9 | getFullName() { 10 | return `${this.firstName} ${this.lastName}`; 11 | } 12 | } 13 | // let user = new User('Carlos', 'Ferreira', 30); 14 | // console.log(user.getFullName()); 15 | class Admin extends User { 16 | getFullName() { 17 | return `Dr. ${this.firstName} ${this.lastName}`; 18 | } 19 | } 20 | let admin = new Admin('Carlos', 'Ferreira', 30); 21 | console.log(admin.getFullName()); 22 | -------------------------------------------------------------------------------- /dist/functions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const add = (a, b) => a + b; 3 | const addWithOptionalTax = (a, b, tax) => { 4 | if (typeof tax != 'undefined') { 5 | return (a + b) - tax; 6 | } 7 | return a + b; 8 | }; 9 | // console.log(addWithOptionalTax(2, 2, 1)); 10 | // console.log(addWithOptionalTax(2, 2)); 11 | const applyDiscount = (price, percentage = 5) => { 12 | return price - (price * (percentage / 100)); 13 | }; 14 | // console.log(applyDiscount(100)); 15 | const calcTotal = (name, ...numbers) => { 16 | let total = 0; 17 | numbers.forEach(num => total += num); 18 | return total; 19 | }; 20 | console.log(calcTotal('Carlos', 2, 3, 5, 10)); 21 | -------------------------------------------------------------------------------- /functions.ts: -------------------------------------------------------------------------------- 1 | const add = (a: number, b: number): number => a + b; 2 | 3 | const addWithOptionalTax = (a: number, b: number, tax?: number): number => { 4 | if (typeof tax != 'undefined') { 5 | return (a + b) - tax; 6 | } 7 | 8 | return a + b; 9 | } 10 | // console.log(addWithOptionalTax(2, 2, 1)); 11 | // console.log(addWithOptionalTax(2, 2)); 12 | 13 | const applyDiscount = (price: number, percentage: number = 5): number => { 14 | return price - (price * (percentage / 100)) 15 | } 16 | // console.log(applyDiscount(100)); 17 | 18 | const calcTotal = (name: string, ...numbers: number[]): number => { 19 | let total = 0; 20 | numbers.forEach(num => total += num) 21 | return total; 22 | } 23 | console.log(calcTotal('Carlos', 2, 3, 5, 10)); 24 | -------------------------------------------------------------------------------- /classes.ts: -------------------------------------------------------------------------------- 1 | class User { 2 | protected readonly firstName: string; 3 | protected lastName: string; 4 | protected age: number; 5 | 6 | constructor(firstName: string, lastName: string, age: number) { 7 | this.firstName = firstName; 8 | this.lastName = lastName; 9 | this.age = age; 10 | 11 | // this.validate(); 12 | } 13 | 14 | public getFullName() { 15 | return `${this.firstName} ${this.lastName}`; 16 | } 17 | } 18 | // let user = new User('Carlos', 'Ferreira', 30); 19 | // console.log(user.getFullName()); 20 | 21 | class Admin extends User { 22 | public getFullName() { 23 | return `Dr. ${this.firstName} ${this.lastName}`; 24 | } 25 | } 26 | let admin = new Admin('Carlos', 'Ferreira', 30); 27 | console.log(admin.getFullName()); 28 | -------------------------------------------------------------------------------- /basic_types.ts: -------------------------------------------------------------------------------- 1 | // numbers 2 | let name_var: number = 321; 3 | name_var = 123; 4 | name_var = 1.2; 5 | name_var = 0xFA; 6 | console.log(name_var); 7 | 8 | // booleano 9 | let active: boolean = true 10 | 11 | // string 12 | let firstName = 'Carlos' 13 | let lastName = 'Ferreira' 14 | let fullName: string = `${firstName} ${lastName}` 15 | 16 | // Enums 17 | enum ROLES { 18 | MANAGER = 'manager', 19 | ADMIN = 'Admin', 20 | CEO = 'CEO', 21 | CTO = 'CTO' 22 | }; 23 | function setRole(role: ROLES): void { 24 | 25 | } 26 | setRole(ROLES.CEO); 27 | 28 | // arrays 29 | let names = ['Carlos', 'Eti', 'EspecializaTi', true, 1]; 30 | let names1: string[] = ['Carlos', 'Eti']; 31 | let names2: Array = ['Carlos', 'Eti']; 32 | let names3: Array = ['Carlos', 'Eti', true, 0xFA]; 33 | -------------------------------------------------------------------------------- /dist/basic_types.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // numbers 3 | let name_var = 321; 4 | name_var = 123; 5 | name_var = 1.2; 6 | name_var = 0xFA; 7 | console.log(name_var); 8 | // booleano 9 | let active = true; 10 | // string 11 | let firstName = 'Carlos'; 12 | let lastName = 'Ferreira'; 13 | let fullName = `${firstName} ${lastName}`; 14 | // Enums 15 | var ROLES; 16 | (function (ROLES) { 17 | ROLES["MANAGER"] = "manager"; 18 | ROLES["ADMIN"] = "Admin"; 19 | ROLES["CEO"] = "CEO"; 20 | ROLES["CTO"] = "CTO"; 21 | })(ROLES || (ROLES = {})); 22 | ; 23 | function setRole(role) { 24 | } 25 | setRole(ROLES.CEO); 26 | // arrays 27 | let names = ['Carlos', 'Eti', 'EspecializaTi', true, 1]; 28 | let names1 = ['Carlos', 'Eti']; 29 | let names2 = ['Carlos', 'Eti']; 30 | let names3 = ['Carlos', 'Eti', true, 0xFA]; 31 | -------------------------------------------------------------------------------- /interfaces.ts: -------------------------------------------------------------------------------- 1 | interface UserInterface { 2 | firstName: string; 3 | readonly lastName?: string; 4 | age: number; 5 | 6 | getFullName(): string; 7 | } 8 | 9 | const getUser = (user: UserInterface): string => { 10 | return `${user.firstName} ${user.lastName}, age: ${user.age}`; 11 | } 12 | 13 | // let user = { 14 | // firstName: 'Carlos', 15 | // lastName: 'Ferreira', 16 | // age: 30 17 | // } 18 | 19 | // console.log(getUser(user)) 20 | 21 | class Person implements UserInterface { 22 | firstName: string; 23 | readonly lastName?: string; 24 | age: number; 25 | 26 | constructor(firstN: string, lastN: string, ageU: number) { 27 | this.firstName = firstN; 28 | this.lastName = lastN; 29 | this.age = ageU; 30 | } 31 | 32 | getFullName(): string { 33 | return `${this.firstName} ${this.lastName}` 34 | } 35 | } 36 | let person = new Person('Carlos', 'Ferreira', 30) 37 | console.log(getUser(person)) 38 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "commonjs", /* Specify what module code is generated. */ 29 | // "rootDir": "./", /* Specify the root folder within your source files. */ 30 | // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "resolveJsonModule": true, /* Enable importing .json files. */ 39 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 40 | 41 | /* JavaScript Support */ 42 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 43 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 44 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 45 | 46 | /* Emit */ 47 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 48 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 49 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 50 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 51 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 52 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 53 | // "removeComments": true, /* Disable emitting comments. */ 54 | // "noEmit": true, /* Disable emitting files from a compilation. */ 55 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 56 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 57 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 58 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 59 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 60 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 61 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 62 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 63 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 64 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 65 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 66 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 67 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 68 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 69 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 70 | 71 | /* Interop Constraints */ 72 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 73 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 74 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 75 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 76 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 77 | 78 | /* Type Checking */ 79 | "strict": true, /* Enable all strict type-checking options. */ 80 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 81 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 82 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 83 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 84 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 85 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 86 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 87 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 88 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 89 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 90 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 91 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 92 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 93 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 94 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 95 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 96 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 97 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 98 | 99 | /* Completeness */ 100 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 101 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 102 | } 103 | } 104 | --------------------------------------------------------------------------------