/TypescriptNinja

🐱‍👤 TypescriptNinja - Our TypescriptVerse discoverys.

Typescript

GitHub repo size GitHub last commit

About | Content | How to contribute

Translate for PT-BR

About

🐱‍👤TypescriptNinha - Our Typescript discoverys. from StudyVerse

Project Targets

Docker Study

  1. To learning the fundamentals

TypescriptTools

  1. Abc

Box

Content

What its?

  1. Inference and Annotaion Types

How to do

  1. How to create a ...
  • How to create a ...

Notes

Init ts config 
tsc --init 

Auto compiler
tsc -w

Inference and Annotaion Types

const ann: string = 'test'
const inf = 'test'

Variables Types

// Array
const number_array: number[] = [1, 2, 3]
const string_array: string[] = ['a',  'b', 'c']
const number_array: Array<number> | Array<string> = [1, 2, 3, 'x', 'y']

// ReadOnlyArray

// Tupla
type FourNumbers =  [number, number, number, number]

Type Alias

type ID = string | number

function showId(id: ID) {
	console.log(id)
}

Interface Object

interface Point {
	x: number
	y: number
	readonly z?: number
}

function showPoint(obj: Point) {
	console.log(obj)
}

const coordObj:Point = { x: 45, y: 44 }
showPoint(coordObj)

OBS: "Use a interface quando quiser incrementar propriedades ao longo do código."

Others
// readonly
// Index Signature
// Herança

Literal types

function showDirection(direction: "left" | "right" | "center") {
	console.log(direction)
}

Dom

// Non null assertion operator

Others

1. BigInt
2. Symbol

Narrowing ( Check data and type )

// Typeof 
// Check is undefined
// Instanceof 
// Operator "in"

Functions

:void -> return without
// Generic Function
// Constraint 

Destructuring

interface Product {
    name: string
    price: number
    isAvailable?: boolean
}

function showProductDetails({ name, price, isAvailable = false }: Product): string {
    return `The product name is: ${name} and he cost R$:${price} and available is ${isAvailable}`
}

console.log(showProductDetails({ name: 'Short', price: 5.55 }));
console.log(showProductDetails({ name: 'T-Short', price: 45.55, isAvailable: true }));

How to contribute

  • Make a fork;
  • Create a branch with your feature: git checkout -b my-feature;
  • Commit changes: git commit -m "feat: my new feature;
  • Make a push to your branch: git push origin my-feature.

After meging your receipt request to done, you can delete a branch from yours.

Made by 👨🏾‍💻 VictorPereira