Typescript 第三方模块中[交叉口?]冲突的解释和解决?
我在尝试将Typescript 第三方模块中[交叉口?]冲突的解释和解决?,typescript,react-native,Typescript,React Native,我在尝试将方向属性放在可动画上时遇到此错误。查看来自反应本机可动画: Type '{ children: Element; animation: string; iterationCount: "infinite"; direction: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<AnimatableProperties<V
方向
属性放在可动画上时遇到此错误。查看来自反应本机可动画
:
Type '{ children: Element; animation: string; iterationCount: "infinite"; direction: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<AnimatableProperties<ViewStyle> & ViewPr...'.
Type '{ children: Element; animation: string; iterationCount: "infinite"; direction: string; }' is not assignable to type 'Readonly<AnimatableProperties<ViewStyle> & ViewProps>'.
Types of property 'direction' are incompatible.
Type 'string' is not assignable to type 'never'.
我找出了冲突的来源-ViewProps
实际上定义为:
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-native/index.d.ts
export interface FlexStyle
{
...
direction?: "inherit" | "ltr" | "rtl";
...
}
export interface LayoutProps extends FlexStyle {}
export interface ViewProps
extends ViewPropsAndroid, ViewPropsIOS, GestureResponderHandlers, Touchable, AccessibilityProps, LayoutProps
{
...
}
因此FlexStyle
直接位于属性中,而不是样式中
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-native/legacy-properties.d.ts
import {
...
ViewProps,
...
} from "react-native";
declare module "react-native" {
...
export type ViewProperties = ViewProps;
...
}
// https://github.com/facebook/react-native/blob/master/Libraries/Components/View/ViewPropTypes.js
export type ViewProps = {
// there's no direction property here or [seemingly] on TVViewProps
} & TVViewProps;
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-native/index.d.ts
export interface FlexStyle
{
...
direction?: "inherit" | "ltr" | "rtl";
...
}
export interface LayoutProps extends FlexStyle {}
export interface ViewProps
extends ViewPropsAndroid, ViewPropsIOS, GestureResponderHandlers, Touchable, AccessibilityProps, LayoutProps
{
...
}