简体   繁体   English

打字稿与JavaScript语法

[英]Typescript vs javascript syntax

I am trying to take some javascript and translate it into typescript in order to use it with a webpage that will utilize Aurelia. 我正在尝试使用一些JavaScript并将其翻译成打字稿,以便与将利用Aurelia的网页一起使用。 I am having some syntax issues with the below lines. 我在以下几行中遇到一些语法问题。 If anyone can point me in the right direction on this would be most appreciated. 如果有人能指出我正确的方向,将不胜感激。 Lines are below. 线在下面。 Thanks in advance 提前致谢

--Jason -杰森

//trying to see if the browser supports HTML5 FileReader functionality
//VS currently says filereader does not exist on type 'Window'
      if (window.filereader) 

//VS says Property 'trigger' does not exist on type 'HTMLElement'
      document.getElementById('fileBox').trigger('click');

//VS says Property 'click' does not exist on type 'Element'
       document.querySelector('.fileCont span').click(function () {
    this.remove();
});


  // Property 'file' does not exist on type 'HTMLImageElement'
     var img = document.createElement("img");
     img.file = file;

For types that haven't yet made it into the standard definition file, you can extend the interface to include the additional properties : 对于尚未纳入标准定义文件的类型,您可以扩展接口以包括其他属性

interface Window {
    filereader: any;
}

if (window.filereader) {

} 

If you are using a library, for example jQuery, you can grab a ready-made definition for that . 如果您使用的是库(例如jQuery),则可以获取一个现成的定义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM