Add basic typescript integration

This commit is contained in:
Isidor Nygren 2022-04-21 16:23:37 +02:00
parent a937b82cd2
commit a817ed17a2
8 changed files with 46 additions and 12 deletions

View file

@ -21,14 +21,18 @@ import cockpit from 'cockpit';
import React from 'react';
import { Alert, Card, CardTitle, CardBody } from '@patternfly/react-core';
interface ApplicationState {
hostname: string;
}
const _ = cockpit.gettext;
export class Application extends React.Component {
constructor() {
super();
export class Application extends React.Component<unknown, ApplicationState> {
constructor(props: unknown) {
super(props);
this.state = { hostname: _("Unknown") };
cockpit.file('/etc/hostname').watch(content => {
cockpit.file('/etc/hostname').watch((content: string) => {
this.setState({ hostname: content.trim() });
});
}

View file

@ -21,7 +21,7 @@ import "./lib/patternfly/patternfly-4-cockpit.scss";
import React from 'react';
import ReactDOM from 'react-dom';
import { Application } from './app.jsx';
import { Application } from './app';
/*
* PF4 overrides need to come after the JSX components imports because
* these are importing CSS stylesheets that we are overriding

5
src/types/cockpit.ts Normal file
View file

@ -0,0 +1,5 @@
declare module 'cockpit' {
export function gettext(prop: string): string;
export function file(prop: any): any;
export function format(...prop:any): any;
}