Typescript 为什么可以';t我使用StyleProp<;视图样式>;在我自己的组件上
我正在使用TypeScript/Vscode编写我的React本机应用程序。我希望在自定义组件上完成样式的代码,就像React Native自己的Typescript 为什么可以';t我使用StyleProp<;视图样式>;在我自己的组件上,typescript,react-native,visual-studio-code,intellisense,typescript3.0,Typescript,React Native,Visual Studio Code,Intellisense,Typescript3.0,我正在使用TypeScript/Vscode编写我的React本机应用程序。我希望在自定义组件上完成样式的代码,就像React Native自己的视图组件一样 stylepropView定义如下: style?: StyleProp<ViewStyle>; 我得到以下错误: Type '{ style: { top: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAt
视图
组件一样
style
propView
定义如下:
style?: StyleProp<ViewStyle>;
我得到以下错误:
Type '{ style: { top: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<MyViewProps, never>, any, any>> & Readonly<Pick<MyViewProps, never>> & Readonly<...>'.
Property 'style' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<MyViewProps, never>, any, any>> & Readonly<Pick<MyViewProps, never>> & Readonly<...>'.ts(2322)
类型“{style:{top:number;};}”不可分配给类型“IntrinsicattAttributes&IntrinsicClassAttributes&Readonly&Readonly”。
类型“IntrinsicatAttributes&IntrinsicClassAttributes&Readonly&Readonly”上不存在属性“style”。ts(2322)
我做错了什么
(只是澄清一下:该样式在运行时非常有效,我无法使用的只是代码完成/智能感知)如果您不关心动画视图的话
键入MyViewProps={style?:ViewStyle};
如果您确实关心
动画。查看
类型maybeanimate=T | Animated.Value;
键入AnimatedScalar=string | number;
类型AnimatedStyle={
[Key in keyof T]:T[Key]扩展动画标量
?可能是动物化的
:T[Key]扩展数组
?数组,因为我在这里找到了99%的答案。
<MyView style={{top:-20}}/>
Type '{ style: { top: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<MyViewProps, never>, any, any>> & Readonly<Pick<MyViewProps, never>> & Readonly<...>'.
Property 'style' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<MyViewProps, never>, any, any>> & Readonly<Pick<MyViewProps, never>> & Readonly<...>'.ts(2322)