2022-09-12
09:00-17:00 / 17:00-19:00 / 21:00~22:00 / 23:00-24:00
let a: number[] = [1,2];
let b: string[] = ["il","1"];
let c: boolean[] = [true, false];
const player : object ={
name:"nico"
}
player.name
const player:{
name:string,
age?:numbeer,
}={
name:"nick"
}
type Name = string;
type Age= number;
type Player = {
readonly name:Name,
age?:Age
}
const nico: Player ={
name:"nico"
}
const lynn: Player ={
name:"lynn",
age:12
}
function playerMaker(name:string):Player{
return {
name
}
}
const playerMaker =(name:string) :Player =>{{name}}
const nico = playerMaker("nico")
nico.age =12
const numbers: readonly number[]=[1,2,3,4]
numbers.push(1) //error;
const names : readonly string[] = ["1","2"]
["nico",12,false]
const player: readonly[string, number, boolean] =[
"nico",1,true]
let a:unknown;
if(typeoof a==="number"){
let b = a+1
}
if(typeof a ==="string"){
let b = a.toUpperCase();
}
void : 아무것도 return 하지 않는 함수
function hello():void{
console.log("x")
}
const a = hello();
never: 함수가 절대 return을 하지 않을 때
function hello():never{
throw new Error("xxx")
}
function hello (name:string|number){
if(typeof name==="string"){
name
}else if (typeof name ==="number"){
name
}else {
name
}
}
call signatures
function add(a:number,b:number):number{
return a+b
}
const add=(a:number,b:number)=>a+b
typed Add= (a:number,b:number)=>number;
const add:Add = (a,b)=>a+b
overloading : 여러 개의 call signatures 가 있는 경우!!
type Add = {
(a:number, b:number) :number
(a:number, b:string) :number
}
const add :Add = (a,b)=>{
if(typeof b === "string") return a
return a+b
}
router.push("/home") // string로 보내기
router.push({
path:"/home",
}) //object로 보내기
type Push= {
(path:string):void
(obj)
}
concrete vs generic
type SuperPrint = {
(arr:number[]):void
(arr:boolean[]):void
(arr:string[]):void
(arr:(number|boolean)[]):void
}
const superPrint :SuperPrint = (arr)==>{
arr.forEach(item=>console.log(item))
}
superPrint([1,2,3,4])
superPrint([true,false,true])
superPrint(["a","b","c"])
superPrint([1,2,,true,false])
type SuperPrint ={
<T>(arr:T[]):T
}
const superPrint:SuperPrint = (arr)=>{
arr.forEach(i=>console.log(i))
}
type SuperPrint = (a:any[])=>any
const superPrint :SuperPrint = (a)=>a[0]
const d= superPrint([1,2,true,false,"hello"])
d.toUpperCase() // error
type SuperPrint = <T,M>(a:T[],b:M)=>T
function superPrint<T>(a:T[]){
return a[0]
}
const a = superPrint([1,2,3,4])
const b = superPrint([true,false,true])
type Player<E> ={
name:string
extraInfo:E
}
const nico: Player<{favFood:string}>={
name:"nico",
extraInfo:{
favFood:"Kimchi"
}
}
type Player<E>={
name:string
extraInfo: E
}
type NicoExtra={
favFood:string
}
type NicoPlayer = Player<NicoExtra>
const nico: NicoPlayer={
name:"nico"
extraInfo:{
favFood:"kimchi"
}
}
const lynn: player<null>={
name:"lynn"
extraInfo:null
}
type A =number[]
type A= Array<number>
let a:A = [1,2,3,4]
출처: 노마드코더 타입스크립트 - 블록체인
Monday/ Wednesday(Tuesday)/ Thursday 19:45-20:15 (English with Clarisse)
Tuesday / Thursday 21:00 ~ 22:00 (어깨 수영 보류)
Saturday 09:00~10:00
Sunday