[September,12th, 2022]

devbit4 [front-end developer]·2022년 9월 12일
0

TIL

목록 보기
106/163
post-thumbnail

업로드중..

2022-09-12

✍️ PLAN & TODO

  • 26일부터 스터디이이이 start
  • 그전까지 Typescript project
  • introduction

💻 1) CODING

09:00-17:00 / 17:00-19:00 / 21:00~22:00 / 23:00-24:00

✍️ WORK & CODE


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
  • readonly 기능
const numbers: readonly number[]=[1,2,3,4]
numbers.push(1) //error;

const names : readonly string[] = ["1","2"]
  • Tuple
["nico",12,false]

const player: readonly[string, number, boolean] =[
"nico",1,true]
  • unknown: 변수의 타입을 알지 못할 때
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))
}
  • any와 generic의 차이점 (generic: 요구한 대로 signature를 생성해 줄 수 있는 도구)
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]

출처: 노마드코더 타입스크립트 - 블록체인

🤸‍♀️ 3) EXERCISE & LANGUAGES

Monday/ Wednesday(Tuesday)/ Thursday 19:45-20:15 (English with Clarisse)
Tuesday / Thursday 21:00 ~ 22:00 (어깨 수영 보류)
Saturday 09:00~10:00
Sunday


🏈 4) REFLECTION


profile
제대로 꾸준하게 / 블로그 이전 => https://dailybit.co.kr

0개의 댓글