I am trying to export a function inside of a class in Typescript. I am able to export the class, and use it as an import inside of another class. However, when I try to use the function, it gives me the error as follows
Property 'formatBytes' does not exist on type 'typeof Landing'.
I am attempting to export the function formatBytes inside the Landing class and use it as Landing.formatBytes inside the Modules class.
Exported class
import * as React from 'react';
export default class Landing extends React.Component<{}, SomeState> {
public formatBytes(bytes: number, decimals: number): string {
return 'something';
}
public componentDidMount(): void {
// code
}
public render(): JSX.Element {
const { items } = this.state;
return (
<div>
</div>
);
}
}
Imported class
import * as React from 'react';
import Landing from './Landing'
export default class Modules extends React.Component<
{},
IDetailsListModulesState
> {
constructor(props: {}) {
super(props);
const _columns: IColumn[] = [
{
onRender: (item: IDetailsListModuleItem) => {
return (
<span>
{Landing.formatBytes(item.sizeDifference, 3)}
</span>
);
}
},
];
this.state = {
};
}
public componentDidMount(): void {
}
public render(): JSX.Element {
}
}