Professional Documents
Culture Documents
*to install Typescript compiler and more (is a superset programming lang of Javascript)
tsc –v
tsc file-name.ts
npm init
*to enable us install third-party packages & their dependencies into our project
*to install lite server so that we don’t need to reload page for every change on ts file (but we still
compile the file)
Now go to created package json and in scripts write “start”:”lite-server” the new added package
Then run:
npm start
Overview
Types
Course outline
Typescript basics
Compiler & configuration deep dive
--------------------------------
Generics
Decorators
----------------------------
Types
Core syntax and feats.
string (`Hi`)
const person: {key1: type1; key2: type2;} = {key: val1, key2:val2} ou const per: {} = {assignments} ou
const person: object = {assignments}
array[1, 2, 3]
let hobbies: *string[]; hobbies = [“Água”, “Pão”]; ou let hobbies: any[]; hobbies = [“Ág”, 1, true]
*enum to create a custom type. They receive numbers by default from 0 on or you can assign to them
(other data types or mix).
any *
Types alias
Undefined
Function
Sum = add;
ou
*declare that a var receives a specific type of function, its params and return type
Unknown
Never
Ctrl + c
tsc (--w)*
tsc --init
*all files in this directory’ll be compiled once saved. For many files
In tsconfig.json file:
, “include”: [“”]
, “files”: []
, “sourceMap”: true
, “outDir”: “./pathName” normally dist folder is the one for the output, and src for our ts files
, “removeComments”: true
, “noEmit”: true
“noEmitOnError”: true
*to not gererate js files when ts ones are compiled with errors
nameID: number;
nameLocal: string;
this.nameLocal = local;
Generics
Creates reusable components in Typescript. Which makes ts. apps adaptable and scalable over time.
return args;}
*a generic function that deals with the type and not the values of fnctions and their params.
zeroValue: NumType;
myGen.zeroValue = 0;
npx create-react-app
node file.js
if(“swim” in pet){
return pet.swim();
} return pet.fly();}
email: "joyous@jackal.com";
age: 21;
“dependencies”: {
“@typescript/lib-dom”:”npm:@types/web”}}
…name: arrayType
interface IComplexType{
id: number;
*mechanism to determine what properties, methods, and objects must implement. Practically is only to
guarantee right types to be used.
interface Point{
x: number;
readonly y: number;
p1.x = 5;
Implementing Interfaces
interface IPrint{
classA.print();
Class Modifiers
Public
class Pup{
}}
pup.id = 40
Private
*For class property get assignable only inside that class (or its constructor). Can only be externally
accessed by the class setter and getter methods
Static
class Pup{
Pup.id = 40;
Extend
interface IBase{
id: number;}
name: string;}
id: number;
*extends an interface or a class. Interface inheritance. Class can extend and implement in same time
If more than more extend or implementation than use commas, to separate
Protected
public printDetail(){
getDetails(){
getDetails(): string{
Abstract class cannot be instantiated, are just to set functionalities that are shared among a group of
classes
Abtraction, inheritance and encapsulation are the base of OOP
a: string; b: string;}
ou
*in the end of the file to export all its declarations changing their names.
*to import any declaration so that it gets reusable in the current ts file. We can use Alias
*importing all expressions from a file. And access ‘em through Langs.declaration.
namespace Name{
let name = new Name.itsclass();//instantiating a namespace to use its classes and more
*to create a namespace, to avoid similar class names compilation errors. Their like classes. A file may
have more than one namespace. Their declation must be exported to be accessed outside.