草庐IT

language-typescript

全部标签

javascript - 在 TypeScript 中使用 Raphael JavaScript 库

是否可以在TypeScript中使用JavaScript库?例如我想使用Raphael在TypeScript中并将JS文件添加到我的/scripts文件夹并将它们添加到_references.js。但是当我想在我的TS文件中声明时:varr=Raphael(10,50,640,480);Intellisense总是说:Raphaeldoesnotexistinthecurrentscope.并且TS文件不编译。 最佳答案 这一行是环境声明:declarevarRaphael:any;虽然它有效,但您无法真正打字。项目Definite

javascript - react typescript 打字不起作用

通过打字安装后,我在终端中收到以下错误终端错误errorTS2320:Interface'Element'cannotsimultaneouslyextendtypes'ReactElement'and'ReactElement'.Namedproperty'type'oftypes'ReactElement'and'ReactElement'arenotidentical.ERRORin/Users/ajvivek/Dev/ES6/motionize-code/typings/globals/react/index.d.ts(2375,5):errorTS1036:Statement

javascript - typescript 声明第三方模块

我怎样才能声明一个像这样的第三方模块:在第三方模块中:module.exports=functionfoo(){//dosomthing}在我的代码中:import*asfoofrom'foo-module';//Cannotfindadeclarationmodulefor...foo(); 最佳答案 查看documentationonworkingwith3rdpartymodules.如何编写声明在很大程度上取决于模块的编写方式及其导出的内容。您给出的示例是一个CommonJS模块(module.exports=...),它实

javascript - TypeScript 中 'this' 的作用域

我有一个非常简单的类,但在Typescript中定义“this”时已经遇到了麻烦:typescript//////moduleProblem{exportclassIndex{detailsUrl:string;constructor(){$('.problem-detail-button').click((e)=>{e.preventDefault();var$row=$(this).closest('tr');//thismustbethatofthecallbackvarproblemId:number=$row.data('problem-id');$.ajax({url:th

javascript - 在与 TypeScript 的 react 中使用状态

我是TypeScript的新手。我在显示this.state.something时遇到问题在render方法中或将其分配给函数中的变量。看看最重要的一段代码:interfaceState{playOrPause?:string;}classPlayerextendsReact.Component{constructor(){super();this.state={playOrPause:'Play'};}render(){return(this.playPause=playPause}title={this.state.playOrPause}//inthislineIgetanerr

javascript - 是否可以将 ES5 JavaScript 与 Angular 2 而不是 TypeScript 一起使用?

是否需要为Angular2学习TypeScript?Angular2可以与纯JavaScript一起使用吗?编辑:我看到像ES6、ES7、Dart这样的语言会编译成JavaScript来执行,但我还没有看到任何直接使用ES5JavaScript的引用。 最佳答案 是的,你可以。去读这个guide.按代码示例上的ES5选项卡将显示与TypeScript相对的常规ES5JavaScript。APIpreview但是,由于显而易见的原因,它是不完整的。所以你可能还没有找到那里列出的ES5方法,其中一些可能会在发布前发生变化。ES5中Ang

javascript - typescript 推送到数组中的特定键

我正在使用Firebase开发Angular2项目。我需要在this.guestPush中将所有查询结果推送到同一个键下。我有一个包含不同用户级别的多选元素。4、6、9。Whenonelevelisselected,theresultingobjectissavedintheguestPusharray,butwhenanotherlevelisselectedthefollowingerroroccurs.我收到这个错误:ERRORTypeError:this.guestPush[("filter"+i)].pushisnotafunction这是我的代码:guestPush:any

javascript - 使用 get set "exited with code 1"编译 TypeScript 错误代码

gettopLeft(){returnthis._topLeft;}settopLeft(value){this._topLeft=value;Recalc();}上面的代码可以在TypeScriptPlay中找到,但我收到构建错误从VisualStudio2012编译它时错误“退出代码1”有没有人尝试在TypeScript中获取、设置并成功构建? 最佳答案 您需要以ECMAScriptv5为目标,即将-targetES5参数传递给编译器。这需要在项目文件目标配置中设置。我不知道VS是否有任何内置的机制来编辑目标配置,所以我只能告诉

javascript - 如何使用 TypeScript 为无状态、功能性 React 组件指定(可选)默认 Prop ?

我正在尝试在Typescript中创建一个带有可选props和defaultProps的无状态React组件(用于ReactNative项目)。这对于vanillaJS来说是微不足道的,但我对如何在TypeScript中实现它感到困惑。使用以下代码:importReact,{Component}from'react';import{Text}from'react-native';interfaceTestProps{title?:string,name?:string}constdefaultProps:TestProps={title:'Mr',name:'McGee'}constT

javascript - Visual Studio 2017 中用于 JavaScript 和 TypeScript 文件的 Visual Studio Code 颜色主题

如主题所示,我想在VisualStudio2017中为JavaScript和TypeScript文件导入/设置VisualStudioCode颜色主题。因此,我想为其设置颜色主题的文件是:.js、.jsx、.ts和.tsx。如果无法按文件或语言进行编辑,那么我想知道是否可以导入看起来像VisualStudioCode的整个主题。简而言之,我想要这样:看起来像这样: 最佳答案 我终于找到了方法!长话短说:下载JavaScript.tmLanguage和JavaScript.tmTheme.转到%USERPROFILE%\.vs\Ext