Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting a JavaScript React Class Component into a TypeScript file

Is there a way to export a JavaScript React Class Component into a TypeScript file?

I have the following code:

Login.js

class Login extends Component {

constructor(props) {
    super(props);
    this.usernameText = React.createRef();
    this.passwordText = React.createRef();
    this.urlText = React.createRef();
    this.keyPress = this.keyPress.bind(this);
  }

  .
  .   
  .
 }
 export default  Login;

index.ts

const Login = require("./uiManagement/jiraUI/Login/Login");
export {
 Login as JiraUiLogin 
}

In another project i did an npm import for the above to use the login component:

import { Component } from "react";
import { JiraUiLogin } from "infosysta-typescript-core";
class mLogin extends Component {
  render() {
    return (
      <JiraUiLogin />
    )
  }
};
export default mLogin

But I'm having the following error: enter image description here

like image 482
Sora Avatar asked Aug 15 '26 23:08

Sora


1 Answers

What about changing the Login.js file to typescript?

import React, { Component } from "react";

interface Props {
}
interface State {

}

class Login extends Component<Props, State> {
  usernameText = React.createRef<HTMLInputElement>();
  passwordText = React.createRef<HTMLInputElement>();
  urlText = React.createRef<HTMLInputElement>();
  keyPress = (event: React.KeyboardEvent) => {
    
  };
}

export default Login;
like image 120
Codepressed Avatar answered Aug 17 '26 12:08

Codepressed