我有一个TSX组件,它是一个包装其子代的容器,如下所示:
import * as React from "react";
interface IProps extends React.Props<Box> {
}
interface IState {
}
export class Box extends React.Component<IProps, IState> {
render() {
return (
<div>
<h3>Check this out:</h3>
{this.props.children}
</div>);
}
}
Run Code Online (Sandbox Code Playgroud)
我也有一些纯粹的组件,比如这个:
// ReSharper disable once InconsistentNaming - React components must start with a capital letter.
export function LabelTest(props: { label: string }) {
return (
<div style={{ display: "flex" }}>
<label style={{ flex: "1 0 0" }}>{props.label}</label>
<div style={{ width: "auto" }}>
This is …Run Code Online (Sandbox Code Playgroud) typescript reactjs visual-studio-2015 tsx typescript-typings
我正在使用TypeScript和React.我已经定义了我的AppContainer.tsx组件,将其导出为默认值.我在文件app.ts中使用ReactDOM它来生存它以将其呈现给目标dom元素.但我收到以下错误(见图).有关更多信息和GitHub repo的链接,请阅读以下内容.
问题:我在做什么或者解释是什么?从所有代码示例我看到这应该工作 - 但也许(显然)我错过了一些东西.以下是更多信息和完整GitHub仓库的链接.
/// <reference path="../../../typings/index.d.ts" />
// Top level application component
/*------------------------------------------------------------------------------------*/
/** IMPORTS **/
import * as React from 'react';
import { Component } from 'react';
/*------------------------------------------------------------------------------------*/
/*///*/
/*------------------------------------------------------------------------------------*/
/** COMPONENT **/
export default class AppContainer extends React.Component<{}, {}> {
render() {
return ( <div /> );
}
}
/*------------------------------------------------------------------------------------*/
/*///*/ …Run Code Online (Sandbox Code Playgroud) 我正在尝试将这个简单的添加div到我的 .tsx 文件的返回块中:
<div id="bizible.reportUser" style="display:none" data-email="some@email.com"/>
Run Code Online (Sandbox Code Playgroud)
我这样做:
import React from 'react';
import Radium from 'radium';
import Icon from './Icon';
import Header from './Header';
import Colors from '../colors';
const NoMatch = ({ children, title, icon, kind }) => {
return ([
<div style={[styles.base, kind && styles[kind]]}>
<Icon name={icon} style={[styles.icon]} height="48" width="48" />
<Header title={title} style={[styles.header]} />
<p style={[styles.message]}>
{children}
</p>
</div>,
<div id="bizible.reportUser" style="display:none" data-email="some@email.com"/>
]
);
};
Run Code Online (Sandbox Code Playgroud)
但它返回一个错误消息并且不编译:
error TS2322: Type '({children, title, icon, kind}: { children: …Run Code Online (Sandbox Code Playgroud) 尝试启动 gatsby+react+typescript 项目,VSCode 只会将语法突出显示应用于我的 .tsx 文件中的 HTML。打字稿代码保持单一颜色。我该如何解决?
注意:我目前没有安装插件,如果文件类型设置为 .jsx,则突出显示有效
我正在尝试在 React TypeScript 文件中实现这一点:
export class MainInfo extends Component<IProps>{
continue = e => {
e.preventDefault();
this.props.nextStep();
};
render() {
const { values1, handleChange } = this.props
return (
<div>
<Formik
validateOnChange={true}
validationSchema={validationSchema}
initialValues={{ Title: '', ActivationDate: '', ExpirationDate: '', DirectManager: '', HRBP: '' }}
onSubmit={(data) => {
console.log(data)
}}
Run Code Online (Sandbox Code Playgroud)
但是我收到一个参数 'e' 隐含一个 'any' 类型的 React TypeScript 错误。我应该如何解决这个问题?
编辑:我在另一个文件中有这些,我在这里使用它们作为道具
nextStep = () => {
const { step } = this.state;
this.setState({
step: step + 1
});
};
// Go back to …Run Code Online (Sandbox Code Playgroud) 在 TSX 文件中,可以定义通用组件:
const MyComponent = <A,>() => <p>my component</p>
Run Code Online (Sandbox Code Playgroud)
注意,后面的A。
现在,如果我想A默认string,人们自然会认为上面应该写成:
const MyComponent = <A=string,>() => <p>my component</p>
Run Code Online (Sandbox Code Playgroud)
但这不起作用。
我缺少什么?
我正在使用glibc 2.24版本。它具有通过事务同步扩展(例如_xbegin()和_xend())用于pthread_mutex_lock实现的锁省略路径。我认为硬件应该支持锁定删除,因为hle CPU标志用于硬件锁定删除。我正在使用的处理器是采用Skylake架构的Intel®Xeon®Gold 6130。
首先,我想禁用Lock Elision,但是当我运行使用pthread_mutex_lock且具有perf stat -T来监视事务周期的程序时,我得到0。我认为这意味着pthread_mutex_lock根本不使用事务路径。谷歌搜索之后,我发现可能有必要先使用export GLIBC_TUNABLES = glibc.elision.enable = 1来启用锁定清除,但是在此步骤之后,我仍然看不到使用perf进行任何事务。
另一方面,当我包含_xbegin()时;和_xend(); 直接在此过程中,我获得了一些具有perf stat -T的交易周期,这应该意味着我希望能找到与perf匹配的计数器。
因此,有关如何启用锁定清除的任何建议都将有所帮助。还是我检查不正确?
TSX的更新我在主要功能中使用了这两条指令,就像这样:
_xbegin();
_xend();
Run Code Online (Sandbox Code Playgroud)
我不确定它需要哪个库,我已经包含了数十个。对于编译,我使用以下标志:-O3 -march = native -lpthread与该示例相关。
对于锁,我有互斥锁:
pthread_mutex_t * mutex;
mutex = (pthread_mutex_t *) malloc(10 * sizeof(pthread_mutex_t));
for(int k=0; k<10; k++){
pthread_mutex_init(&mutex[k], NULL);
}
Run Code Online (Sandbox Code Playgroud)
也许为了省略,我应该以不同的方式初始化它?
我试图让我的组件接受一个引用。
我有一个像这样的组件:
const MyComponent: RefForwardingComponent<HTMLDivElement, IMyComponentProps> = (props, ref) => {
return <div ref={ref}>Hoopla</div>
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试将 ref 传递给时是这样的:
<MyComponent ref={myRef}></MyComponent>
Run Code Online (Sandbox Code Playgroud)
...我收到此错误:
Property 'ref' does not exist on type 'IntrinsicAttributes & IMyComponentProps & { children?: ReactNode; }'.ts(2322)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在努力理解如何使用 TSX 模板处理 Vue 3 中的自定义事件。
考虑一个简单的父/子应用程序,其中子级向父级发送自定义事件:
const Child = defineComponent({
emits: {
boom: (x: number) => true,
},
setup(props, { emit }) {
console.log("Child props", props)
return () => (
<div onClick={() => emit("boom", 123)}>Click me!</div>
)
},
})
const Parent = defineComponent(() => {
return () => <Child onBoom={(x) => console.log(`Boom: ${x}`)} />
})
Run Code Online (Sandbox Code Playgroud)
上述功能正常,并且:
setup,props是空的(正如我所期望的)。emitchild 中的调用已正确键入(它需要传递一个数字作为参数)。不幸的是,它不知道如何输入onBoom父级:
Property 'onBoom' does not exist on type 'IntrinsicAttributes & Partial<{}> …Run Code Online (Sandbox Code Playgroud) 假设我有这个 monorepo:
/apps
/apps/app1
/apps/app1/src (contains index.ts and many other files and subfolders here)
/apps/app1/tsconfig.json
/apps/app1/package.json
/apps/app2
/apps/app2/src (contains index.ts and many other files and subfolders here)
/apps/app2/tsconfig.json
/apps/app2/package.json
/common
/common/package1
/common/package1/src
/common/package1/src/utility1.ts
/common/package1/src/utility2.ts
/common/package1/tsconfig.json
/common/package1/package.json
/tsconfig.json
/package.json
Run Code Online (Sandbox Code Playgroud)
我只需要 esm 就可以在其中工作。
我怎样才能让 tsx、tsc 或任何其他 ts 工具运行一个或多个使用“common/*/src”中内容的应用程序?基本上不需要将“common”中的内容构建到 dist 文件夹中。
因此,每次我对其中的文件进行更改时,/common当我在监视模式下运行应用程序时,它们都会立即生效。