How would I avoid a type error when attempting to import propertys from a typescript file

I have a typescript class which includes propertys for a connection:

export default class Connection
{
    public IceServer: string;
    public SwitchId: number;
    public AgendId: number;
    public password: string;
}

I am then trying to access these property’s from within a javascript file:

import Connection from './Models/ConnectionDetails';

function Connect() {
  var con = new Connection();
  var postData = {IceServer: con.IceServer, SwitchId: con.SwitchId, AgentId: con.AgendId, Password: con.password};
  JSON.stringify(postData);

  // create JWT
  const token = jwt.sign({iceServer, switchId, agentId, password}, process.env.TOKEN_SECRET);

  MakeRequest('connect', postData, token);

When i run the application it gives me the following error:

image

Does anyone know why this is occuring? Thankyou

If it runs in nodejs or Electron main process, just change file extension from .js to .mjs

If it runs in browser or Electron renderer process and you include it with <script> tag, then add type="module" attribute to the tag

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.