首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >[交集]的解释与解析第三方模块中的冲突?

[交集]的解释与解析第三方模块中的冲突?
EN

Stack Overflow用户
提问于 2018-05-08 12:31:02
回答 1查看 130关注 0票数 0

我在试图将direction属性从react-native-animatable放到Animatable.View上时出错

代码语言:javascript
复制
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'.

通过类型声明(我似乎找不到造成此问题的原因)跟踪的direction AnimatableComponent 似乎是通过 AnimatableProperties**?在AnimatableComponent上明确定义的此外,无论问题是什么,我如何解决它,至少消除错误输出的噪音?此外,我不认为有一种方法可以通过让编译器输出 _it_ 认为最终的**接口?来“打印调试”类型。

direction 是,是 ViewStyle 类型上的属性,但据我所知,这不应该相关。

我想我提取了下面的相关输入:

代码语言:javascript
复制
// https://github.com/oblador/react-native-animatable/blob/master/typings/react-native-animatable.d.ts

import {
  ...
  ViewProperties,
  ViewStyle,
  ...
} from 'react-native';

interface AnimatableProperties<S extends {}>
{
  ...
  direction?: 'normal' | 'reverse' | 'alternate' | 'alternate-reverse';
  ...
}

interface AnimatableComponent<P extends {},S extends {}> extends
  NativeMethodsMixin,
  AnimatableAnimationMethods,
  ClassicComponentClass<AnimatableProperties<S> & P>
{
  ...
}

export const View : AnimatableComponent<ViewProperties,ViewStyle>;
export type View = AnimatableComponent<ViewProperties,ViewStyle>;
代码语言:javascript
复制
// 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;
  ...
}
代码语言:javascript
复制
// 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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-08 14:15:07

我找出了冲突的来源- ViewProps实际上被定义为:

代码语言:javascript
复制
// 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直接位于属性中,而不是样式中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50233708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档