Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 为什么可以';t我使用StyleProp<;视图样式>;在我自己的组件上_Typescript_React Native_Visual Studio Code_Intellisense_Typescript3.0 - Fatal编程技术网

Typescript 为什么可以';t我使用StyleProp<;视图样式>;在我自己的组件上

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

我正在使用TypeScript/Vscode编写我的React本机应用程序。我希望在自定义组件上完成样式的代码,就像React Native自己的
视图
组件一样

style
prop
View
定义如下:

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)