About | Content | How to contribute
Translate for
PT-BR
🐱👤TypescriptNinha - Our Typescript discoverys. from StudyVerse
- To learning the fundamentals
- Abc
- Doc
- Youtube Videos
- Abc
- Courses
- Inference and Annotaion Types
- How to create a ...
- How to create a ...
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 }));
- 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