Я хотел внести свой вклад в библиотеку rn-placeholder для React Native, предоставив типы для DefinitiveTyped .Я впервые добавляю файл index.d.ts
в DefinitiveTyped.
Я написал файл декларации.Теперь я хочу написать обязательный 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 />
}
}
Вот мой tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"jsx": "react",
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "rn-placeholder-tests.ts"]
}
Другие файлы - это только то, как они генерируются при использовании npx dts-gen --dt --name my-package-name --template module
.
Как мне пройти тесты?
РЕДАКТИРОВАТЬ: Я преобразовал rn-placeholder-tests.ts
в .tsx
, что избавляет от ошибки regexp
.Но теперь TSLint жалуется, что не может найти модули:
[ts] Cannot find module 'react'.
[ts] Cannot find module 'react-native'.
[ts] Cannot find module 'rn-placeholder'.
Что происходит?