草庐IT

grunt-typescript

全部标签

javascript - 在 initConfig() 中访问 Grunt 配置数据

如何访问Grunt配置属性site以读取配置属性值指定路径中的project.json文件?grunt.registerTask('build',function(target){grunt.config('site',target);grunt.task.run('foo:dist','bar:dist');});grunt.initConfig({pkg:grunt.file.readJSON('package.json'),site:grunt.file.readJSON('./sites/'+grunt.config('site')+'/project.json')});gru

javascript - TypeScript 中的深度克隆(保留类型)

我需要在TypeScript中深度克隆一个对象。这应该不是问题,因为像Lodash这样的库为此提供了适当的功能。然而,这些似乎丢弃了类型信息。>vara=newSomeClass();>ainstanceofSomeClass;varb=_.cloneDeep(a);>binstanceofSomeClass;有没有办法在保留此键入信息的同时克隆TypeScript中的对象? 最佳答案 Typescript不会在此处丢弃类型信息。在DefinitelyTypedlodash.d.ts文件,你可以看到cloneDeep被定义为clon

javascript - Lodash Flow 和 TypeScript

我一直在关注一篇关于Lodash的文章,Whyusing_.chainisamistake,它突出显示您可以使用Flow消除对链的需求.给出的例子如下使用链import_from"lodash";_.chain([1,2,3]).map(x=>[x,x*2]).flatten().sort().value();可以使用flow转换成下面的importmapfrom"lodash/fp/map";importflattenfrom"lodash/fp/flatten";importsortByfrom"lodash/fp/sortBy";importflowfrom"lodash/fp/

javascript - TypeScript 匿名函数

这个JavaScript的TypeScript等价物是什么?(function(){/*codehere*/})();我试过了()=>{/*codehere*/}但这会产生(function(){/*codehere*/});我需要最后一组额外的括号来执行匿名函数。 最佳答案 (()=>{/*codehere*/})();或者简单地使用JavaScript(同样有效的TypeScript)(function(){/*codehere*/})();...取决于您是否要使用粗箭头捕获this。Playground.

javascript - "let _self = this"在 Javascript/Typescript 中是什么意思?

这个问题在这里已经有了答案:Howdoesthe"this"keywordwork,andwhenshoulditbeused?(22个答案)WhatunderliesthisJavaScriptidiom:varself=this?(10个答案)关闭4个月前。在此codesnippet,为什么this.identifier不起作用但_self.url起作用?getConfig(){let_self=this;returnfunction(){this.page.url=this.url||window.location.href;this.page.identifier=_self.

javascript - Typescript:如何检查 eventTarget 中的 tagName?

为什么在这种情况下:varele=document.getElementById("toolbar");ele.addEventListener("click",function(e){if(e.target.tagName==="SPAN"){console.log(e.target.tagName)}},false);VisualStudio向我显示此错误?Build:Operator'==='cannotbeappliedtotypes'HTMLElement'and'string'.Property'tagName'doesnotexistontype'EventTarget'

javascript - 如何将 package.json 数组传递给 grunt.js

有没有办法从package.json文件中将数组传递给grunt.js?我尝试了几种不同的方法,但似乎都不起作用。我目前有:/*globalmodule:false*/module.exports=function(grunt){//Projectconfiguration.grunt.initConfig({pkg:'',lint:{files:''}//Defaulttask'lintqunitconcatmin'grunt.registerTask('default','lint');};包.json{"lint":["grunt.js","test.js"]}我能找到的唯一解决

javascript - Backbone 和 TypeScript,一段不幸的婚姻 : Building a type-safe "get"?

我正在尝试将TypeScript与Backbone.js结合使用。它“有效”,但是Backbone的get()和set()失去了大部分类型安全。我正在尝试编写一个可以恢复类型安全的辅助方法。像这样:我会把它放在我的模型中:object():IMyModel{returnattributes;//exceptIshoulduseget(),notattributes,perdocumentation}这在消费者中:varmyVar=this.model.object().MyProperty;通过这种语法,我得到了TypeScript的知识,即MyProperty存在并且是bool,这太

javascript - 如何从 typescript 中的嵌套函数中调用函数?

我想从函数func1的示例函数中调用函数func2。有人可以建议实现该目标的方法吗?classA{publicfunc1(){letsample=function(){//callfunc2...buthow?}}publicfunc2(){}}提前致谢 最佳答案 将this关键字与arrow函数符号一起使用,如下所示:classA{publicfunc1(){letsample=()=>{this.func2();}}publicfunc2(){}}技巧是使用arrow函数,因为arrow函数将this的定义更改为的实例class

javascript - 如何在 Typescript 中连接字符串和数字

我正在使用方法获取数据functiondate(){letstr='';constcurrentTime=newDate();constyear=currentTime.getFullYear();constmonth=currentTime.getMonth();constday=currentTime.getDate();consthours=currentTime.getHours();letminutes=currentTime.getMinutes();letseconds=currentTime.getSeconds();if(month作为输出我得到了2017-6-132