This is the first day of my participation in the August More text Challenge. For details, see: August More Text Challenge

1. Installation:

/ / installation
sudo npm install -g typescript

/ / check
tsc -v  // Normally, the TS version is displayed

Copy the code

2. Unloading and reloading:

/ / uninstall typescript
sudo npm uninstall -g typescript

// Find the TSC directory and delete it

where tsc # /usr/local/bin/tsc
cd /usr/local/bin
rm -rf tsc

// Reinstall
sudo npm install -g typescript
Copy the code

3. Basic types:

ECMAScript recently defines eight data types

  • Seven primitive data types
    • Boolean
    • Null
    • Undefined
    • Number
    • String
    • Symbol
    • BigInt
// Boolean type
let isDone:boolean =true;

// Numeric type
let age:number =24;

// The value is a string
let PlayerName:string = "Allen Iverson";

// undefined
let u:undefined =undefined;

// null
let n:null =null;

// The number type can be assigned undefined
let num:number = undefined;

Copy the code

4. Any type and union type:

// Any type: Any type can be assigned

let notSure:any="sdfsdsd";

notSure=24;

notSure=true;

notSure.myname;

notSure.getName();


// Associative types: the following example 🌰 can be numeric or string

let NumorString:number | string =24;

NumorString="Kobe"
Copy the code

5. Array and Tuple:

// Array of numbers
let arrofNumber:number[] = [1.2.3.4.5];

arrofNumber.push(520);

//IArguments
function test(){
    console.log(arguments);
    console.log(arguments.length); // Has the length attribute
    console.log(arguments[0]);  // You can use []

    let igr:IArguments = arguments;
}

// Tuple: specifies the type of each item in the array

let tuple:[string.number] = ["Wade".3];   / / ✅

tuple=["Wade".3."The Miami Heat"];    / / ❎
Copy the code