TypeScript:错误TS2339:属性' CustomEvent'在类型' Window'上不存在

时间:2015-12-06 16:54:21

标签: javascript typescript aurelia aurelia-framework

我正在尝试使用Aurelia指南后面的TypeScriptimport {bindable, autoinject, customElement} from 'aurelia-framework'; import * as $ from 'jquery'; import 'select2'; import 'select2/css/select2.css!'; @customElement('select2') @autoinject export class CustomSelect{ @bindable name:string; @bindable selected: boolean = false; @bindable options: any; element: Element; constructor(element: Element){ this.element = element; } attached() :void { $(this.element) .find('select') .select2() .on('change', ev => { let changeEvent; if(window.CustomEvent){ changeEvent = new CustomEvent('change', { detail: { value: ev.val }, bubbles: true }); } else { changeEvent = document.createEvent('CustomEvent'); changeEvent.initCustomEvent('change', true, true, {value: event.val}); } this.element.dispatchEvent(changeEvent); }); } } 中编写自定义元素。

但是在尝试编译时遇到以下错误:

  

错误TS2339:属性' CustomEvent'类型' Window'。

上不存在      

错误TS2339:财产' val'类型'事件'。

上不存在

我的课程是:

<?php 
/* 
 * Smarty plugin 
 * ------------------------------------------------------------- 
 * File:     function.aff.php 
 * Type:     function 
 * Name:     aff 
 * Purpose:  outputs a random magic answer 
 * ------------------------------------------------------------- 
 */ 
function smarty_function_aff($params, &$smarty) 
    { 
           $affiliateid = $params['affiliateid']; 
           $refflink = 'http://example.com/aff.php?aff=' . $affiliateid .''; 

           print $refflink; 
    } 
?>

1 个答案:

答案 0 :(得分:1)

CustomEventlib.es6.d.ts

中定义

将打字稿编译配置为目标ES6将解决此问题。进行此更改后,您可能需要关闭并重新打开IDE。