문제

image.png

문제 코드


const updatePage = (
    pageId: string,
    updates: { title?: string; icon?: string },
    syncWithServer: boolean = true,
  ) => {
    setPages((prevPages) =>
      prevPages.map((page) => (page.id === pageId ? { ...page, ...updates } : page)),
    );

    if (syncWithServer && clientId && workspace?.id) {
      sendPageUpdateOperation({
        pageId,
        ...updates,
        clientId,
        workspaceId: workspace.id,
      });
    }
  };

해결 코드

const updatePage = (
    pageId: string,
    updates: { title?: string; icon?: string },
    syncWithServer: boolean = true,
  ) => {
    setPages((prevPages) =>
      prevPages.map((page) => (page.id === pageId ? { ...page, ...updates } : page)),
    );

    if (syncWithServer && clientId && workspace!.id) {
      sendPageUpdateOperation({
        pageId,
        ...updates,
        clientId,
        workspaceId: workspace!.id,
      });
    }
  };

원인은?

TypeScript에게 명확하게 "이 값은 반드시 존재한다"고 알려줍니다.

신기하다…!