草庐IT

typescript-typings

全部标签

javascript - TypeScript:如何在编译时声明固定大小的数组以进行类型检查

更新:这些检查适用于编译时,而不是运行时。在我的例子中,失败的案例都在编译时被捕获,我期望其他应该失败的案例有类似的行为。假设我正在编写一个类似表的类,我希望该类的所有成员都是相同长度的数组,例如:classMyClass{tableHead:string[3];//expecttobea3elementarrayofstringstableCells:number[3];//expecttobea3elementarrayofnumbers}目前我找到的最接近的解决方案是:classMyClass{tableHead:[string,string,string];tableCells

javascript - Typescript 和 jQuery 类型。导入 jquery 类型的正确方法?

是否可以包含jquery.d.ts并使用jQueryStatic类型?我需要类似的东西...protectedel:jQueryStatic;...无论我如何尝试,我都无法从https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/jquery导入jQueryStatic接口(interface)非常感谢。更新///errorTS2304:Cannotfindname'jQuery'.///import{jQuery}from'jquery';errorTS2305:Module'"jquery"'hasnoexpor

javascript - 从 TypeScript 扩展数组

我在下面的代码中做错了什么?我正在尝试在我的类MyNumberList上扩展Array,然后尝试使用它。我看到的是似乎没有任何项目被添加到列表中。当我尝试访问列表元素时,我得到一个undefined。P.S我正在使用TypeScript1.8.2classMyNumberListextendsArray{constructor(...numbers:number[]){//lookslikethisisnotworkingsuper(...numbers);}}letstatusCodes:MyNumberList=newMyNumberList(10,20,30);console.l

javascript - 检查 typescript 类是否有 setter/getter

我有一个具有以下属性的typescript类:exportclassapiAccount{private_balance:apiMoney;getbalance():apiMoney{returnthis._balance;}setbalance(value:apiMoney){this._balance=value;}private_currency:string;getcurrency():string{returnthis._currency;}setcurrency(value:string){this._currency=value;}...我需要为这个类创建一个空白实例:l

javascript - 如何在 TypeScript 中使用 moment-duration-format?

我在我的TypeScript(Ionic2/Angular2)项目中使用moment.js。继thispost,我现在想试用一个插件moment-duration-format我有npm包和类型定义,可以通过importas..使用。importmomentfrom'moment';...letduration=moment.duration(decimalHours,'hours');我现在想使用moment-duration-format我通过npminstallmoment-duration-format--save安装,然后通过npmi@types/moment-duratio

javascript - 找不到 Karma + Jasmine + TypeScript + Webpack 的源映射

我正在尝试使用Karma、Jasmine和Webpack测试(覆盖)我的TypeScript应用程序。通过以下,我能够成功运行测试,但无法正确生成覆盖率。我正在使用karma-remap-coverage(https://github.com/sshev/karma-remap-coverage),它看起来很简单。它看起来好像发生了一些有趣的事情(而且我得到了某种覆盖率报告)但是在这里和那里进行了一些调整,数字发生了巨大变化,我永远无法真正加载源map。这是基本设置:我有一个src目录,其中包含10个.ts文件。目前只有一个有相应的.spec文件。spec文件非常简单,足以证明我可以运

javascript - 错误 : Enzyme Internal Error: unknown composite type undefined

我在尝试应用enzyme时遇到此错误,但我找不到任何相关问题。这是test.js;importReactfrom'react';importAccountLoginFormfrom'./LoginPage';importsinonfrom'sinon';import{mount,shallow,configure}from'enzyme';import{expect}from'chai';importAdapterfrom'enzyme-adapter-react-15';importconfigureStorefrom'redux-mock-store';configure({ada

javascript - TypeError [ERR_INVALID_ARG_TYPE] : The "original" argument must be of type Function. 接收类型未定义

在下面的代码中,我得到了这个错误:TypeError[ERR_INVALID_ARG_TYPE]:The"original"argumentmustbeoftypeFunction.Receivedtypeundefinedconstsqlite3=require('sqlite3').verbose();constutil=require('util');asyncfunctiongetDB(){returnnewPromise(function(resolve,reject){letdb=newsqlite3.Database('./project.db',(err)=>{if(e

javascript - <input type "multiple"> 中的条件 ="file"属性与 AngularJS

我需要一个上传表单字段,它可能允许也可能不允许用户选择多个文件。我知道我可以做类似的事情:但是,我们知道这并不理想。我试过了但这行不通。似乎AngularJShasnosuchngMultipledirective,但是everyoneisusingitanyway(或者我错过了什么?)无论如何,实现该目标的最佳方法是什么?编辑:从目前的答案来看,似乎没有很好的方法可以做到这一点。我在他们的跟踪器上打开了这个问题,让我们看看我们得到了什么:-)https://github.com/angular/angular.js/issues/7714 最佳答案

javascript - 你能在 TypeScript 接口(interface)中定义字符串长度吗?

我有一个这样的结构:structtTest{charfoo[1+1];charbar[64];};我有TypesScriptexportinterfacetTest{foo:string;bar:string;}有没有办法将[64]和[1+1]添加到类型中? 最佳答案 正如评论所说:js/ts不支持char类型,无法声明数组/字符串长度。不过,您可以使用setter强制执行:interfacetTest{foo:string;}classtTestImplementationimplementstTest{private_foo:s