interface FunctionComponent<P = {}> {
(props: P, context?: any): ReactElement<any, any> | null;
propTypes?: WeakValidationMap<P> | undefined;
contextTypes?: ValidationMap<any> | undefined;
defaultProps?: Partial<P> | undefined;
displayName?: string | undefined;
}
to
interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
propTypes?: WeakValidationMap<P> | undefined;
contextTypes?: ValidationMap<any> | undefined;
defaultProps?: Partial<P> | undefined;
displayName?: string | undefined;
}
这个解决方法对我起到了作用。
在项目根目录下创建一个名为 framer-motion.d.ts
的文件,并添加以下代码片段。
import * as React from 'react';
declare module 'framer-motion' {
export interface AnimatePresenceProps {
children?: React.ReactNode;
}
}
'"framer-motion"' has no exported member named 'AnimatePresence'. Did you mean 'AnimatePresenceProps'?
- 有什么想法吗? - Byron CoetseeSimpleComponent
的props类型声明包装在PropsWithChildren<{...}>
中来解决它。function SimpleComponent(props: PropsWithChildren<{
prop1: string;
prop2: number;
...
}>) {
return <div>...</div>;
}