node.js - Typescript + mitt NPM-paket: Kunde inte hitta en deklarationsfil för modulen
Jag har ett React-komponentbibliotek som jag importerar med NPM och jag försöker konvertera det till TypeScript.
import React from 'react';
import SvgIcon from '@myapp/ui/components/SvgIcon'; //<---------------- not working
function App() {
return (
<SvgIcon />
);
}
export default App;
Men Typescript fortsätter att klaga på att jag inte har deklarationerna:
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';`
Men när jag öppnar node_modules ser det ut som om mitt bibliotek är korrekt uppsatt?
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.FC<React.SVGAttributes<SVGSVGElement> & React.ImgHTMLAttributes<SVGSVGElement>>;
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) => JSX.Element;
export { SvgIcon };
node_modules/@myapp/ui/components/SvgIcon.js:
Vad missar jag?
UPPDATERING: Jag uppdaterade det med ett exempel på en komponent helt konverterad till Typescript

