I feel like I am missing the smallest thing here, however for some reason when I am trying to build this very simple button component, it is giving me an error about the Component
class not being assignable to type PComponent
(Both things inside the @inductiveautomation/perspective-client
library that I have not messed with in my install.
Am I missing something here?
src/components/button.tsx
/**
* Example of a component which displays an Button, given a URL.
*/
import * as React from 'react';
import {
Component,
ComponentMeta,
ComponentProps,
PComponent,
PropertyTree,
SizeObject
} from '@inductiveautomation/perspective-client';
export const COMPONENT_TYPE = "example.input.button";
export interface ButtonProps {
text: string;
}
export class Button extends Component<ComponentProps<ButtonProps>, any> {
render() {
const { props: { text }, emit } = this.props;
return (
<div { ...emit() }>
{text}
</div>
);
}
}
export class ButtonMeta implements ComponentMeta {
getComponentType(): string {
return COMPONENT_TYPE;
}
getViewComponent(): PComponent {
return Button;
}
getDefaultSize(): SizeObject {
return ({
width: 360,
height: 360
});
}
getPropsReducer(tree: PropertyTree): ButtonProps {
return {
text: tree.readString("text", "")
};
}
}
package.json
{
"name": "@me/dumb-button",
"version": "0.0.1",
"description": "A stupid button that won't compile",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "webpack --mode production"
},
"dependencies": {
"@inductiveautomation/perspective-client": "2.1.34",
"axios": "^0.28.0",
"react": "16.14.0",
"react-dom": "16.14.0"
},
"devDependencies": {
"@types/react": "16.8.8",
"@types/react-dom": "16.8.3",
"css-loader": "^6.1.2",
"mini-css-extract-plugin": "^2.6.0",
"ts-loader": "^9.2.9",
"typescript": "4.2.3",
"webpack": "^5.93.0",
"webpack-cli": "4.9.2"
}
}
tsconfig.json
{
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"*": [
"*"
]
},
"jsx": "react",
"module": "commonjs",
"noEmit": false,
"outDir": "dist/",
"pretty": true,
"sourceMap": true,
"strict": true,
"target": "es6",
"lib": [
"es6",
"dom",
"es7",
"es2017"
],
"forceConsistentCasingInFileNames": true,
"types": [
"react",
"react-dom"
]
},
"include": [
"./src/**/*.ts",
"./src/**/*.tsx"
],
"exclude": [
"node_modules",
"dist"
]
}
The error itself:
ERROR in /Users/kgamble/Work/Ignition/modules/My Modules/dumb-button/web/src/components/Button.tsx
./src/components/Button.tsx 53:2-16
[tsl] ERROR in /Users/kgamble/Work/Ignition/modules/My Modules/dumb-button/web/src/components/Button.tsx(53,3)
TS2322: Type 'typeof Button' is not assignable to type 'PComponent'.
Type 'typeof Button' is not assignable to type 'ComponentClass<ComponentProps<PlainObject, PlainObject>, any>'.
Types of parameters 'props' and 'props' are incompatible.
Type 'ComponentProps<PlainObject, PlainObject>' is not assignable to type 'Readonly<ComponentProps<ButtonProps, PlainObject>>'.
Types of property 'props' are incompatible.
Property 'text' is missing in type 'PlainObject' but required in type 'ButtonProps'.
I appreciate any advice!