I developed a custom React component library to be consume on a private npm. All my components are Typescript React Class Components and in many I used interfaces to declare which props are optional or required. Example:
export interface ICardLinkProps {
Title: string;
Description: string;
ActionText: string;
DestinationUrl?: string;
ImageUrl?: string;
Icon?: string;
Theme: Theme;
}
export class CardLink extends React.Component<ICardLinkProps> {
/// component Code.
}
All the components work as expected but when my coworkers install de package the intellisense does not show the required props. Example:
In contrast if I consume a component from Material-UI the intellisense shows all required and optional props.
Does anyone have an idea on Why I am not getting the intellisense for my components? I'm using rollup to export build the package, this is my configuration:
import typescript from "rollup-plugin-typescript2";
import commonjs from "rollup-plugin-commonjs";
import external from "rollup-plugin-peer-deps-external";
import resolve from "rollup-plugin-node-resolve";
import url from "rollup-plugin-url";
import PeerDepsExternalPlugin from "rollup-plugin-peer-deps-external";
import pkg from "./package.json";
export default {
input: "src/index.ts",
output: [
{
file: pkg.main,
format: "cjs",
exports: "named",
sourcemap: true
},
{
file: pkg.module,
format: "es",
exports: "named",
sourcemap: true
}
],
plugins: [
url({
include: ['**/*.ttf', '**/*.png'],
limit: Infinity
}),
PeerDepsExternalPlugin(),
external(),
resolve(),
typescript({
rollupCommonJSResolveHack: true,
exclude: "**/__tests__/**",
clean: true
}),
commonjs({
include: ["node_modules/**"],
namedExports: {
"node_modules/react/react.js": [
"Children",
"Component",
"PropTypes",
"createElement"
],
"node_modules/react-dom/index.js": ["render"],
'node_modules/react-is/index.js': [
'isElement',
'isValidElementType',
'ForwardRef',
'Memo',
'isFragment'
],
'node_modules/prop-types/index.js': [
'elementType'
]
}
})
]
};
Here is my tsconfig.json
{
"compilerOptions": {
"outDir": "dist",
"module": "esnext",
"target": "es5",
"lib": [
"es6",
"dom",
"es2016",
"es2017"
],
"sourceMap": true,
"allowJs": false,
"jsx": "react",
"declaration": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"typeRoots": [
"src/types"
]
},
"include": [
"src"
],
"exclude": [
"node_modules",
"dist",
"src/**/*.stories.tsx",
"src/**/*.test.tsx"
]
}
Here is the dist folder after runing rollup -c:
This is the contents of the CardLink.d.ts
import React from "react";
import { ICardLinkProps } from "./ICardLinkProps";
/**
* CardLink Component
* @extends {Component<ICardLinkProps,ICardLinkState>}
*/
export declare const CardLink: React.ComponentType<Pick<Pick<ICardLinkProps, "theme" | "classes"> & Partial<Pick<ICardLinkProps, "Title" | "Description" | "ActionText" | "DestinationUrl" | "ImageUrl" | "Icon" | "Secondary">> & Partial<Pick<{
Title: string;
Description: string;
ActionText: string;
DestinationUrl: string;
ImageUrl: string;
Icon: string;
Secondary: boolean;
}, never>>, "Title" | "Description" | "ActionText" | "DestinationUrl" | "ImageUrl" | "Icon" | "Secondary"> & import("@material-ui/core").StyledComponentProps<"centeredIcon" | "icon" | "bellowMargin" | "paper" | "paperSecondary" | "iconSecondary" | "container" | "actionsArea">>;
Thanks in advance.