草庐IT

user-defined-types

全部标签

javascript - typescript TS2322 : Type 'typeof Foo' is not assignable to type 'IFoo'

我正在尝试使用ES2015模块语法和TypeScript组合一些类。每个类在.d.ts文件中实现一个接口(interface)。这是问题的MWE。在.d.ts文件中我有:interfaceIBar{foo:IFoo;//...}interfaceIFoo{someFunction():void;//...}我的导出是://file:foo.tsexportdefaultclassFooimplementsIFoo{someFunction():void{}//...}//noerrorsyet.我的导入是:importFoofrom"./foo";exportclassBarimple

javascript - Uncaught ReferenceError : google is not defined

我想使用地理定位和方向功能,但出现googleisnotdefined错误。代码如下:functionloadScript(){varscript=document.createElement('script');script.type='text/javascript';script.src="https://maps.googleapis.com/maps/api/js?key=mykey&sensor=true"+"&callback=initialize";document.body.appendChild(script);}loadScript好像不行了!varmapOpti

javascript - 如何防止警告 'Property MyProp1 never defined on MyObject' ?

我有一些包含JSON字符串的HTML。在DOM就绪回调中,我有这样的东西:MyObject=JSON.parse($('#TheJsonString').html());稍后在我的代码中,我写了一些这样的东西:varSomeVar=MyObject.MyProp1;然后当我通过Google闭包编译器运行代码时,我收到了警告PropertyMyProp1neverdefinedonMyObject.应该如何编写代码才不会产生警告? 最佳答案 消除警告的最简洁方法是定义JSON的结构。这可以使用@type标签来完成:/**@type{{

javascript - 流: Dynamically generate string union types?

假设我有一个流类型Suit,我想将它组合成另一种名为Card的类型。//types.jstypeSuit=|"Diamonds"|"Clubs"|"Hearts"|"Spades";typeCard={...suit:Suit,...}与其直接在suit.js中对Suit字符串进行硬编码,不如根据JavaScript原语(数组)动态生成Suit类型?说...//constants.jsconstSUITS=['Diamonds','Clubs','Hearts','Spades'];通过这种方式,西装只需定义一次,并且可以在JavaScript结构中定义,该结构将在应用程序的其他部分中

javascript - angular2js : Uncaught Reference Error: System is not defined

我是Angular的新手,所以请帮忙。我在尝试使用带有Angularng-controller标签的Angular运行简单代码时遇到错误,我在其中显示html中的变量,该变量在javascript文件中定义为:varMainController=function($scope){$scope.message="harsh";并在html中显示如下:htmlpagechrome控制台上的错误如下:UncaughtReferenceError:Systemisnotdefined(anonymousfunction)@angular2.js:3098指向angular2js中的某个函数:S

javascript - 王牌编辑器 "define is not defined"

我正在尝试添加aceeditor到我的应用程序。我从github下载它,将“ace/lib/ace”目录放到我的应用程序目录中,包括:"在我的正文标签中:editor=ace.edit"editor"在我的脚本标签中。我尝试在Chrome和Firefox中加载页面,但在ace.js:46中出现“未定义定义”。ace.js中的行是:define(function(require,exports,module){有谁知道为什么ace期望define()函数存在,为什么找不到它?这是我的来源:sometextvareditor=ace.edit("editor");

javascript - Angular 2 : Type 'Subscription' is not assignable to type

我创建了一个非常小的应用程序来从json文件中获取国家并将其绑定(bind)到下拉列表。countries.jsonexportclassCountry{id:number;name:string;}factory.service.tsimport{Injectable}from'@angular/core';import{Http,Response}from'@angular/http';import{Observable}from'rxjs/Observable';import{Country}from'./shared/country';@Injectable()exportcl

javascript - "Resource interpreted as script but transferred with MIME type text/html."

很抱歉,如果这实际上是重复的,但我还没有设法找到我的问题的答案。我使用jQuery的$.getScript加载脚本。但它会导致以下错误:ResourceinterpretedasscriptbuttransferredwithMIMEtypetext/html.该问题仅在MacOS下的Safari中出现如果查看从服务器收到的header,它们包含Content-Type:application/x-javascript,所以我真的不明白问题出在哪里。 最佳答案 Resourceinterpretedasscriptbuttransf

javascript - 咕噜 requirejs 'define is undefined'

我正在尝试使用GruntJS优化RequireJS,使用grunt-contrib-requirejs插件。问题是我的代码在优化之前工作正常,然后在优化之后,在控制台上显示UncaughtReferenceError:defineisnotdefined。这是Gruntfile.jsmodule.exports=function(grunt){grunt.loadNpmTasks('grunt-contrib-requirejs');grunt.initConfig({requirejs:{compile:{options:{name:'main',baseUrl:".",mainCo

javascript - Uncaught ReferenceError : ga is not defined

我想知道人们点击特定按钮的次数(使用Google分析应该非常简单)。但是,我从谷歌控制台收到“UncaughtReferenceError:gaisnotdefined”错误,无法找到修复方法。我在头部添加了这个:(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*newDate();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.asy