在使用@react-spring/web的animated组件时发现了一个类型错误,有issue:https://github.com/pmndrs/react-spring/issues/2358
但是我没找到解决方案
所以决定自己修改原类型文件,注意⚠️这只是个临时的解决办法,尚不清楚对其他类型是否有影响
添加补丁:
diff --git a/node_modules/@react-spring/web/dist/react-spring_web.modern.d.ts
b/node_modules/@react-spring/web/dist/react-spring_web.modern.d.ts
index f647f1b..a18ef5c 100644
--- a/node_modules/@react-spring/web/dist/react-spring_web.modern.d.ts
+++ b/node_modules/@react-spring/web/dist/react-spring_web.modern.d.ts
@@ -24,7 +24,9 @@ type AnimatedComponent<T extends ElementType> = ForwardRefExoticComponent<Animat
}>>;
/** The props of an `animated()` component */
type AnimatedProps<Props extends object> = {
- [P in keyof Props]: P extends 'ref' | 'key' ? Props[P] : AnimatedProp<Props[P]>;
+ [P in keyof Props]: P extends 'ref' | 'key' | 'children' ? Props[P] :
AnimatedProp<Props[P]>;
+} & {
+ children?: React.ReactNode;
};
type StyleProps = Merge<CSSProperties, TransformProps>;
type StylePropKeys = keyof StyleProps;
不知道怎么添加补丁可以看:怎么修改node_modules里的文件,怎么使用patch-package修改node_modules的文件,怎么修改第三方库原文件。-优快云博客