'How to set the type of the value received with getServerSideProps in next js?
I am trying to receive the value received by getServerSideProps as props from ProjectList, but the error is the binding element 'testCases' has an implicit type 'any' ts(7031). So, I am trying to assign TestCaseT, but if ({testCases}):TestCaseT is set, the 'TestCaseT' type does not have a 'testCases' property. ts(2339) is displayed. If you set it to any, the error disappears. How to apply TestCaseT type to testCases?
import styled from "styled-components";
import Header from "../modules/projectList/components/header";
import Main from "../modules/projectList/components/main";
import WithHeader from "../modules/layout/components/WithHeader";
import axios from "axios";
import { useDispatch } from "react-redux";
import { setTestCases } from "../global/project";
import { TestCaseT } from "../global/project";
const ProjectList = ({ testCases }: TestCaseT) => { // here is error!!!
const dispatch = useDispatch();
if (testCases) {
dispatch(setTestCases(testCases));
}
return (
<WithHeader>
<Wrapper>
<Main />
</Wrapper>
</WithHeader>
);
};
export default ProjectList;
const Wrapper = styled.div`
display: flex;
flex-direction: column;
min-width: 1100px;
height: 100%;
align-items: center;
`;
export async function getServerSideProps() {
const res = await axios.get(`test-cases`);
const testCases = res.data;
return {
props: { testCases },
};
}
And TestCaseT is
export interface TestCaseT extends NewTestCaseT {
id: number;
created_at?: string;
pages_thumbnail: string[];
pages_name: string[];
pages_is_dev: boolean[];
error_count?: number;
}
export interface NewTestCaseT {
name: string;
description?: string;
defaultResolution: { width: number; height: number };
isConfirmed: boolean;
project_id: number;
designers_id: number[];
developers_id: number[];
tags_id: number[];
pages_id: number[];
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
