我正在尝试从Typescript中的一个功能创建一个<GeoJSON {...} /> react元素,但没有成功。(我使用的是react-leaflet + Typescript)对于常规的js,我只需要这样做:
<Map
{...}
<GeoJSON
data={...} <- Here I put my feature in JSON format
style={...} <- Associated style
/>
/>
但是在Typescript中,如果我尝试做完全相同的事情,
为了提供一些条件呈现逻辑,我试图将现有的react组件(React)封装到一个高阶组件(HoC)中。我面临的困难是让TypeScript生成一个将HoC包装器和包装组件属性结合在一起的组件。
例如:
import React from "react";
import Select from "react-select";
interface HOCProps {
foo: string
}
// Return a type with the HOCProps properties removed.
type WitoutPrefilled<T e
我有一个REACT-STATELESS-COMPONENT,在一个与TypeScript的项目中。它有一个错误,说,
Missing return type on function.eslint(@typescript-eslint/explicit-function-return-type)
我不知道它要我做什么。这是我的代码:
import React, { Fragment} from 'react';
import IProp from 'dto/IProp';
export interface Props {
prop?: IProp;
}
c
我在我的反应应用程序中使用打字记录。我想严格检查传递给我的组件的道具类型,如果不匹配就抛出错误。
import React from "react";
import styles from "./ServiceDetailCard.css";
type Service = {
amount: string;
comments: string;
};
interface IProps {
service: Service;
myFunc: (count: number) => void; // The function p
我正在创建一个自定义组件,脚本是使用React的钩子用TypeScript编写的
我的组件将使用我的一些类型记录类型,并将其与TextInput类型混合(这样我就可以访问TextInput支持)
这是我的自定义组件示例代码
import { Animated, Platform, TextInput, TextInputProps, View } from 'react-native'
type PropsType = TextInputProps & { //Or should I using TextInput instead of TextInputProps?
当使用Typescript在React中定义道具时,默认的React道具似乎会被任何界面所覆盖。有没有一种干净利落的方法来合并这两种方式,而不必指定React已经知道的每一个属性?
示例:
interface IProps { // extends React.???
title: string;
// Generally seen adding children?: any
// But this can get out of hand with onClick, onChange, etc
}
function MyComponent(props: IProps) {
我正在按照教程在Typescript上使用React和Redux构建聊天应用程序,但在导出我的连接组件时遇到错误:
Type 'InferableComponentEnhancerWithProps<ConnectedState & ConnectedDispatch, OwnProps>'
is missing the following properties from type 'Component<OwnProps, {}, any>':
context, setState, forceUpdate, render, a
我在React和typescript中使用插槽系统。问题是我找不到一个包含slot作为属性的接口,所以我从我的typescript检查器中得到一个错误: Property 'slot' does not exist on type 'IntrinsicAttributes & IStockProps & { children?: ReactNode; }'.
我如何输入一个typescript变量,以便它需要一个设置了key的组件? 我想要这样的东西: const foo: ReactElementWithKey = <div key="some key"></div>
// all ok
const bar: ReactElementWithKey = <div></div>
// no `key` - typescript should show an error 我应该如何定义ReactElementWithKey? 我尝试过这样的方法: type ReactElemen
我正在尝试从TypeScript 2.3.2迁移到2.4.2。
此代码过去在2.3中起作用:
class Records {
public save(): Records {
return this;
}
}
class User extends Records {
public update(): User {
return this.save();
}
}
let myUser: User = new User();
let obj = myUser.update();
但现在,它会在编译时引发以下错误:
错误:(10,5) TS2322:输入“记录”
我正在用写TypeScript。专案应该接受比包装组件多一个支柱,所以我写了以下文章:
type HocProps {
// Contains the prop my HOC needs
thingy: number
}
type Component<P> = React.ComponentClass<P> | React.StatelessComponent<P>
interface ComponentDecorator<TChildProps> {
(component: Component<TChildProp