简体   繁体   English

ReScript,TypeScript:找不到模块“@rescript/react/src/ReactDOM.gen”或其相应的类型声明

[英]ReScript, TypeScript: Cannot find module '@rescript/react/src/ReactDOM.gen' or its corresponding type declarations

I am gradually rewriting an application with React to TypeScript into ReScript.我正在逐渐将使用 React 的应用程序改写为 TypeScript 到 ReScript。 I've already implemented few components in ReScript, but this is the first one, where I use ReactDOM.Style.t as property to my component.我已经在 ReScript 中实现了一些组件,但这是第一个,我使用ReactDOM.Style.t作为我的组件的属性。

Here is my minimized component code:这是我最小化的组件代码:

@genType
@react.component
let make = (~sx: option<ReactDOM.Style.t>=?) => {
  <div></div>
}

ReScript compiles fine (except a warning that sx is not used, but we can ignore it). ReScript 编译得很好(除了没有使用sx的警告,但我们可以忽略它)。

I have the following bs.js generated, which seems to be fine:我生成了以下bs.js ,这似乎很好:

// Generated by ReScript, PLEASE EDIT WITH CARE

import * as React from "react";

function InhypedIcon(Props) {
  return React.createElement("div", undefined);
}

var make = InhypedIcon;

export {
  make ,

}
/* react Not a pure module */

And the following corresponding .gen.tsx file, which causes the problem:以及以下相应的.gen.tsx文件,这会导致问题:

/* TypeScript file generated from InhypedIcon.res by genType. */
/* eslint-disable import/first */


import * as React from 'react';

// @ts-ignore: Implicit any on import
import * as InhypedIconBS__Es6Import from './InhypedIcon.bs';
const InhypedIconBS: any = InhypedIconBS__Es6Import;

import type {Style_t as ReactDOM_Style_t} from '@rescript/react/src/ReactDOM.gen';

// tslint:disable-next-line:interface-over-type-literal
export type Props = { readonly sx?: ReactDOM_Style_t };

export const make: React.ComponentType<{ readonly sx?: ReactDOM_Style_t }> = InhypedIconBS.make;

This does not compile, I am getting TypeScript error:这无法编译,我收到 TypeScript 错误:

TypeScript error in /app/src/icons/InhypedIcon.gen.tsx(11,48):
Cannot find module '@rescript/react/src/ReactDOM.gen' or its corresponding type declarations.  TS2307

     9 | const InhypedIconBS: any = InhypedIconBS__Es6Import;
    10 |
  > 11 | import type {Style_t as ReactDOM_Style_t} from '@rescript/react/src/ReactDOM.gen';
       |                                                ^
    12 |
    13 | // tslint:disable-next-line:interface-over-type-literal
    14 | export type Props = { readonly sx?: ReactDOM_Style_t };

I do understand, that TS can not find rescript/react/src/ReactDOM.gen , however I am not really know why.我明白,TS 找不到rescript/react/src/ReactDOM.gen ,但我真的不知道为什么。 Any ideas how this can be fixed?有什么想法可以解决这个问题吗?

My package versions:我的 package 版本:

node: v16.6.2

"typescript": "^4.1.2"
"rescript": "^9.1.4"
"@rescript/react": "^0.10.3"

Thank you.谢谢你。

This is because rescript bindings to react do not come with GenType, so in case you want it, you have to type it yourself:这是因为 GenType 不附带响应的 rescript 绑定,所以如果你需要它,你必须自己输入:

@genType.import(("react", "CSSProperties"))
type reactStyle = ReactDOM.Style.t

@genType
@react.component
let make = (~sx: option<reactStyle>=?) => {
  <div></div>
}

This should work.这应该有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块“react-lazily”或其相应的类型声明 - Cannot find module 'react-lazily' or its corresponding type declarations VueJS/Typescript - 找不到模块“./components/Navigation”或其相应的类型声明 - VueJS/Typescript - Cannot find module './components/Navigation' or its corresponding type declarations 找不到模块“module.css”或其相应的类型声明 - Cannot find module 'module.css' or its corresponding type declarations 找不到模块“graphql-hooks”或其相应的类型声明 - Cannot find module 'graphql-hooks' or its corresponding type declarations 找不到模块“./App.svelte”或其对应的类型声明 - Cannot find module './App.svelte' or its corresponding type declarations codesandbox - 找不到模块 PACKAGE 或其相应的类型声明 - codesandbox - Cannot find module PACKAGE or its corresponding type declarations React,Storybook - TS2307:找不到模块“按钮”或其相应的类型声明 CAN SB RESOLVE? - React,Storybook - TS2307: Cannot find module 'Button' or its corresponding type declarations CAN SB RESOLVE? 找不到模块“@react-navigation/native”或其相应的类型声明 - Cannot find module '@react-navigation/native' or its corresponding type declarations React Native Typescript babel-plugin-module-resolver 错误:找不到模块或其对应的类型声明 - React Native Typescript babel-plugin-module-resolver error: Cannot find module or its corresponding type declerations 在 vercel 上部署我的 next.js 项目,找不到模块“react-icons/Fa”或其相应的类型声明 - deploy my next.js project on vercel, Cannot find module 'react-icons/Fa' or its corresponding type declarations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM