Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
JavaScript / TypeScript issue with HTML

I have been developing in JavaScript a long time ago. Lately I was asked to do some work with client side scripting so I decided to look into TypeScript, to avoid some of JavaScript pitfalls. My problem is probably basic but I could not find an answer that would be clear to me with my lack of TypeScript / new JavaScript development over the last 10 years. Here it is - I have three files -

1. index.html
2. Globals.ts
3. Drawings.ts

Index.html is the file to be served, in it a JavaScript will arrange and interact with the user. Globals.ts - simply contain my global variables / constants Drawing.ts - contain the Drawing functions for the data, it is referencing globals.ts for the global definitions, with this statement /// <reference path="globals.ts"/>.

In index.html I use the SCRIPT tag with src='Drawings.ts' right under the HEAD Tag.

<SCRIPT lang='JavaScript' src='Drawing.ts'></SCRIPT>
<SCRIPT lang='JavaScript'>local code goes here</SCRIPT>

All the globals in the Global.ts are declared with the word var and assigned a value, like this -

    var x_scale_h_offset = 15;
    var y_scale_v_offset  = 15;
    var g_general_margin  = 10;
    var g_std_font_height  = 10;
    var dpi = 1;

After checking for document complete status I call the init_d() function from Drawings.ts which looks like this -

function init_d()
{
    dpi = window.devicePixelRatio;
}

I get a runtime Uncaught exception dpi is not defined.

I was under the impression that variables declared in a file which are not part of an object are global to all scripts. I also assume - which I might be wrong - that this reference statement /// <reference path="globals.ts"/> will cause Globals.ts to be loaded.

Can someone explain - in simplicity - what am I doing wrong and how to fix it?

Regards

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda