我试图在装载机props 中使用参数props ,因为我使用的是Typescript ,我定义的参数如下所示,但Typescript 对我大喊大叫我不知道为什么? 请以任何我能避开的方式将此告知,提前谢谢.
Type '({ params }: CustomLoaderFunctionArgs) => Promise<any>' is not assignable to type 'LoaderFunction<any>'.
Type '({ params }: CustomLoaderFunctionArgs) => Promise<any>' is not assignable to type '(args: LoaderFunctionArgs<any>) => DataFunctionValue | Promise<DataFunctionValue>'.
Types of parameters '__0' and 'args' are incompatible.
Type 'LoaderFunctionArgs<any>' is not assignable to type 'CustomLoaderFunctionArgs'.
Type 'LoaderFunctionArgs<any>' is not assignable to type '{ params: { id: string; }; }'.
Types of property 'params' are incompatible.
Property 'id' is missing in type 'Params<string>' but required in type '{ id: string; }'.ts(2322)
patient-form.tsx(45, 66): 'id' is declared here.
components.d.ts(61, 5): The expected type comes from property 'loader' which is declared here on type 'IntrinsicAttributes & RouteProps'
(property) loader: ({ params }: CustomLoaderFunctionArgs) => Promise<any>
No quick fixes available
function App() {
const router = createBrowserRouter(
createRoutesFromElements(
<Route path="/" element={<RootLayout />}>
<Route index element={<IndexPage />} />
<Route path="about" element={<ContactPage />} />
<Route path="sign-in" element={<SignInPage />} />
<Route path="sign-up" element={<SignUpPage />} />
<Route path="dashboard" element={<DashboardLayout />}>
<Route index element={<DashboardPage />} loader={patientsDataLoader} />
<Route path="patient/:id" element={<PatientForm initialData={null} />} loader={patientDataLoader}/>
</Route>
</Route>
)
);
return <RouterProvider router={router} />;
}
export default App;
export const patientDataLoader = async ({params} : {params: {id: string}}) => {
const response = await axios.get(`http://localhost:3000/api/patient/${params.id}`);
return response.data;
}