Typescript 如何为DefinitelyTyped的React本机库编写测试?
我想通过提供的类型为React Native库做出贡献。这是我第一次提供一个Typescript 如何为DefinitelyTyped的React本机库编写测试?,typescript,react-native,typescript-typings,definitelytyped,type-declaration,Typescript,React Native,Typescript Typings,Definitelytyped,Type Declaration,我想通过提供的类型为React Native库做出贡献。这是我第一次提供一个index.d.ts文件来定义类型 我写了申报文件。现在我想编写强制性的rn placeholder tests.ts文件。但是,当我尝试使用我的声明时,会出现regexp错误: [ts] Conversion of type 'RegExp' to type 'View' may be a mistake because neither type sufficiently overlaps with the other
index.d.ts
文件来定义类型
我写了申报文件。现在我想编写强制性的rn placeholder tests.ts
文件。但是,当我尝试使用我的声明时,会出现regexp
错误:
[ts]
Conversion of type 'RegExp' to type 'View' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'measure' is missing in type 'RegExp'.
我甚至试着从@types/react native
复制测试,它们给出了相同的错误:
import * as React from 'react';
import { Text, View } from "react-native";
class CustomView extends React.Component {
render() {
return <View />
}
}
其他文件就是使用npx dts gen--dt--name my package name--template module
时如何生成的
我怎样才能通过考试
EDIT:我将rn占位符tests.ts
转换为.tsx
,从而消除了regexp
错误。但现在TSLint抱怨它找不到模块:
[ts] Cannot find module 'react'.
[ts] Cannot find module 'react-native'.
[ts] Cannot find module 'rn-placeholder'.
发生了什么?将.ts更改为.tsx是文件扩展名的右移。(请参阅此处有关tsx的更多信息:) 有关其他“找不到模块”错误,请参见此 可能需要添加类型定义:
npm i -D @types/react
或者,您可能只需要将“moduleResolution”添加到tsconfig.json文件中:
"compilerOptions": {
...
"moduleResolution": "node" <---------- this entry
...
}
“编译器选项”:{
...
“moduleResolution”:“node”将.ts更改为.tsx是文件扩展名的右移。(请参阅此处有关tsx的更多信息:)
有关其他“找不到模块”错误,请参见此
可能需要添加类型定义:
npm i -D @types/react
或者,您可能只需要将“moduleResolution”添加到tsconfig.json文件中:
"compilerOptions": {
...
"moduleResolution": "node" <---------- this entry
...
}
“编译器选项”:{
...
“moduleResolution”:“节点”