💡 참고
database 주소가 바뀌면 codegen.yml 파일과 _app.tsx 파일을 수정해줘야 한다.
codegen.yml 파일을 수정하면 재실행(타입스크립트 최신화) 해야 한다. 재실행 명령어:yarn generate
[대괄호]나 {중괄호}로 선언한 경우에는, 타입을 적어주는 위치가 다르다.
const [함수] = useMutation<결과 타입, 변수 타입>(쿼리);
<Pick<Imutation, "함수">
IMutation함수Args
형태로 이름이 지어져있다.import 필수!
data가 없을 수 있기 때문에 뜨는 에러다. 아래처럼 바꾸면 에러 사라짐 👇🏻
mutation과 동일하다.
위에서 사용한 Pick은 utility 타입이라고 부른다.
유틸리티 타입
interface IProfile {
name: string;
age: number;
school: string;
hobby?: string;
}
type IPartialProfile = Partial<IProfile>;
type IRequiredProfile = Required<IProfile>;
type IPickProfile = Pick<IProfile, "name" | "age">;
type IOmitProfile = Omit<IProfile, "school">;
// ZZZ에 들어있는게 키가 되고 IProfile이 value가 된다. 각각에 프로필 타입이 생긴다.
type IUnion = "철수" | "영희" | "훈이"; // Union 타입
type IRecordProfile = Record<IUnion, IProfile>;
type IKeyofProfile = keyof IProfile;
const key: IKeyofProfile = "age";
interface IProfile {
name: string
age: number
school: string
hobby?: string
}
//같은 이름의 interface
interface IProfile {
candy: number
}
const profile: Partial<IProfile> = {
name: "주희",
candy: 1,
};