본문 바로가기

개발/Web

[TypeScript] Data type

Boolean

let isBool: boolean = True; //true/flase  

Number

let num: number = 7;  
let hexNum: number = 0xf0c0;  
let binaryNum: number = 0b00100;  
let octalNum: number = 0o23;  

String

let str: string = "hello";  
let sentence: string = ':) ${str} world';  

Array

let list: number\[\] = \[1,2,3\];  
let list: arry = \['a', 'b', 'c'\]  

Tuple

let a: \[number, string\];  

Enum


enum abc {a, b, c}

let a: abc = abc.a;

let num: string = abc\[0\];

Any


let a: any = 7;

a = "hello";

a = true

let list: any\[\] = \[7, true, "hello"\]

void


function func(): void {

a = " nothing return "

}

Null & Undefined


let a: undefined = undefined;

let b: null = null;

Never

function error(message: string): never {


throw new Error(message);


}

Type assertions

let somthing: any = "string";

let change: str= <string>someValue;

let change: str= someValue as string;

'개발 > Web' 카테고리의 다른 글

웹 프로젝트의 흐름  (0) 2020.03.06
[TypeScript] Abstract Class & Interface  (0) 2020.03.05
Cookie, Session  (0) 2020.03.04
HTTP 프로토콜  (0) 2020.03.04
개발자 도구  (0) 2020.02.27