Transition继承 CSSTransitionProps 编译错误
来源:7-9 拿来主义 - 自定义 Transition 组件编码第二部分

布鲁斯基
2020-10-19
问题
版本:
- @types/react-transition-group@4.4.0
- react-transition-group@4.4.1
- react@16.14.0
- typescript@3.7.2
在 7-8 Transition 组件课中, 继承 CSSTransitionProps
时, 按照老师的写法用 interface 继承, typescript 编译报错, 并且提示 属性不存在.
interface TransitionProps extends CSSTransitionProps {
animation?: AnimationName,
wrapper? : boolean,
}
IDE 警告:
An interface can only extend an object type or intersection of object types with statically known members.
使用组件也会出现 ts 的错误
Property 'in' does not exist on type 'IntrinsicAttributes & TransitionProps & { children?: ReactNode; }'.
type TransitionProps = CSSTransitionProps & {
animation?: AnimationName,
}
改 interface 为 type 别名就可以了, 想请问老师这是什么原理啊?
写回答
1回答
-
张轩
2020-10-20
同学你好 请看常见问题欧 https://coding.imooc.com/learn/questiondetail/176079.html
解释的非常清楚
312020-10-20
相似问题