Машинописный текст мой пакет NPM: Не удалось найти файл декларации для модуля

#node.js #reactjs #typescript

#node.js #реагирует на #машинописный текст

Вопрос:

У меня есть библиотека компонентов React, которую я импортирую с помощью NPM, и я пытаюсь преобразовать ее в машинописный текст.

 import React from 'react'; import SvgIcon from '@myapp/ui/components/SvgIcon'; //lt;---------------- not working  function App() {  return (  lt;SvgIcon /gt;  ); }  export default App;  

Однако Typescript продолжает жаловаться, что у меня нет деклараций:

 Could not find a declaration file for module '@myapp/ui/components/SvgIcon'. '/Users/edmundmai/Documents/my-app/node_modules/@myapp/ui/components/SvgIcon.js' implicitly has an 'any' type.  Try `npm i --save-dev @types/myapp__ui` if it exists or add a new declaration (.d.ts) file containing `declare module '@myapp/ui/components/SvgIcon';`  

Но когда я открываю node_modules, похоже, что моя библиотека настроена нормально?

введите описание изображения здесь

node_modules/myapp/ui/package.json :

 {  ...  "main": "./index.js",  "types": "./index.d.ts", }  

node_modules/@myapp/ui/index.js :

 'use strict';  Object.defineProperty(exports, '__esModule', { value: true });  var components_SvgIcon = require('./components/SvgIcon.js'); require('./tslib.es6-46449784.js'); require('react'); require('styled-components'); require('./constants/properties.js');    exports.SvgIcon = components_SvgIcon["default"];    

node_modules/@myapp/ui/index.d.ts :

 import React from 'react'; import { SVG_ICON_COLORS, SVG_ICON_SIZES } from './constants/properties';  interface Props {  icon: React.FClt;React.SVGAttributeslt;SVGSVGElementgt; amp; React.ImgHTMLAttributeslt;SVGSVGElementgt;gt;;  stroke?: SVG_ICON_COLORS;  fill?: SVG_ICON_COLORS;  size?: SVG_ICON_SIZES;  alt_text?: string;  className?: string; } declare const SvgIcon: ({ stroke, fill, size, icon: Icon, className, alt_text, }: Props) =gt; JSX.Element;  export { SvgIcon };    

node_modules/@myapp/ui/components/SvgIcon.js :

введите описание изображения здесь

Что я упускаю?

ОБНОВЛЕНИЕ: Я обновил его примером компонента, полностью преобразованного в Typescript