Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.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/batch-file/6.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
Javascript 样式不是';t应用于我用TypeScript创建的React库_Javascript_Css_Reactjs_Typescript - Fatal编程技术网

Javascript 样式不是';t应用于我用TypeScript创建的React库

Javascript 样式不是';t应用于我用TypeScript创建的React库,javascript,css,reactjs,typescript,Javascript,Css,Reactjs,Typescript,我制作了一个React库&在examples/文件夹中向该组件添加了样式,但没有应用样式 下面是示例/index.tsx文件: import 'react-app-polyfill/ie11'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import { ReactTypical } from '../.'; const App = () => { const hypeText = [

我制作了一个React库&在
examples/
文件夹中向该组件添加了样式,但没有应用样式

下面是
示例/index.tsx
文件:

import 'react-app-polyfill/ie11';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ReactTypical } from '../.';

const App = () => {
  const hypeText = ['Creator', 'Entrepreneur', 'Doer', 'Lone Wolf'];
  return (
    <>
      <ReactTypical
        style={{
          color: 'red',
          fontSize: 256,
        }}
        steps={hypeText.flatMap(hype => [hype, 5000])}
        loop={Infinity}
      />
    </>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));
export type Props = {
  steps: Array<any>;
  loop: number;
  className?: string;
  wrapper?: keyof JSX.IntrinsicElements;
} & React.HTMLAttributes<HTMLOrSVGElement>;
我认为
React.HTMLAttributes
包含每个React HTML属性,因此
style
必须在那里可用


有什么我做错了吗?

您的库接受任何
React.HTMLAttributes
,但不使用它们,也不传递它们

你需要这样的东西:

const Typical = ({ steps, loop, className, wrapper: Wrapper = 'p', ...otherProps }: Props) => {

...

return React.createElement(Wrapper, {
  ...otherProps,
  ref: typicalRef,
  className: typicalStyles,
});

谢谢你的工作。需要打字吗?我的意思是,
otherProps
的类型是什么?或者我应该这样保留它吗?不。
otherProps
Props
Props
的子集。Typescript应该自动处理这个问题。