TypeScript 정리

김용희·2022년 1월 29일
0

let age :JSX.Element =

내용
; //컴포넌트 jsx 타입지정
const output = useSelector( (state :{count: number}) => state);
const output = useSelector( (state :RootState) => state); //리덕스에서가져온 타입
const dispatch :Dispatch = useDispatch(); //디스패치 날릴때 해당 액션타입 쓰게 정의
따로 tpye 빼내서 정의

type tempType = {address:string, job:number}
function User(props :tempType) :JSX.Element
interface로 정의

interface arrLength {
count: number
}
const initial :arrLength= {count:0};
페이로드 액션은 리듀서에서 어떤 액션타입이 들어가는지 정의

randomss(state, action :PayloadAction<number>){  // 페이로드액션은 액션에 어떤타입들어가는지
  state.count += action.payload
},

name : string | undefind
name? : string

함수타입은 () =>{}
함수표현식에만 type alias

type 지정할타입명 = (a :string) => number;

let 함수 :함수타입명 = function(a) {
return 10
}

일반 변수나 함수는 type
오브젝트는 interface

유니온 타입, 둘다들어올떄,
function hamsu(a: string | undefined){
if( a && typeof a === 'string') {

} a가 언디파인이면 실행안되고 스트링이면 실행 narrowing

}

타입모르면 :any 쓰면됨 하지만 그러면 ts 쓰는 이유가없어짐

function 함수(x :unknown[]){
return x[0]
}

interface arrLength {
length: number
}

function check(x: tempType){
return x.length
}
let a = 함수<string[]>(['100'])

let age :JSX.Elemnet =

내용

fucn

function user() : JSX.Element {
return

프로필입니다

}

profile
He threw his knapsack over the brick wall

0개의 댓글