草庐IT

flow-typed

全部标签

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 - 在JavaScript事件处理中,为什么 "return false"或 "event.preventDefault()"和 "stopping the event flow"会有区别?

据说当我们处理一个“点击事件”时,返回false或者调用event.preventDefault()是有区别的,其中thedifferenceisthatpreventDefaultwillonlypreventthedefaulteventactiontooccur,i.e.apageredirectonalinkclick,aformsubmission,etc.andreturnfalsewillalsostoptheeventflow.那是不是说,如果click事件被多次注册了好几个action,用$('#clickme').click(function(){…})返回fals

javascript - 使用flowtype静态检查mocha测试代码

我有一些复杂的Mocha代码,我想用FlowType进行静态检查,为什么不呢?下面是一个最小的重现:/*@flow*/describe('it',function(){it('fails',function(){consts:number='flowspotsthiserror';});});当我对此运行Flow时,Flow确实发现了将string分配给number的问题,这表明该方法在某种程度上是有效的。但是,我也得到:test/test.js:44:describe('it',function(){^^^^^^^^identifier`describe`.Couldnotresol

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 - 如何使用 Flow 键入默认导出?

如何使用Flow键入默认导出?Flow有办法做到这一点吗?期望的结果://index.jstypecomplexThing={a:string}typeThing={x:number,y:boolean,z:complexThing}exportdefault{x:0,y:true,z:{a:'hello'}}:Thing//thissaysmydefaultexportisaThing可接受的替代方案:或者,我不介意内联输入每个对象属性,但我认为这在句法上是不可能的:exportdefault{//Idon'tknowhowtoaddtypesignaturesherex:0,//n

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 - React.PropTypes.node 的 Flow 等价物是什么?

React.PropTypes.node的Flow等价物是什么(即React可以渲染的任何东西,如果有的话?我必须自己创建它作为联合类型吗?换句话说,这里用什么替换????typeProps={children:???,}constUselessComponent:(props:Props)=>React$Element=({children})=>({children})UselessComponent.propTypes={children:React.PropTypes.node.isRequired,} 最佳答案 看来还是个

javascript - typescript TS7015 : Element implicitly has an 'any' type because index expression is not of type 'number'

我在Angular2应用程序中遇到此编译错误:TS7015:Elementimplicitlyhasan'any'typebecauseindexexpressionisnotoftype'number'.导致它的代码是:getApplicationCount(state:string){returnthis.applicationsByState[state]?this.applicationsByState[state].length:0;}但这不会导致此错误:getApplicationCount(state:string){returnthis.applicationsBySt

javascript - 尝试使用 gh-pages 部署我的 React 应用程序但收到此错误消息 : The "file" argument must be of type string. Received type undefined

我试图用gh-pages部署我的React应用程序,但我遇到了这个错误:"file"参数必须是字符串类型。接收类型未定义。起初,我以为这是我的代码,所以我制作了另一个没有修改的create-react-app,尝试使用npmrundeploy命令进行部署,但再次收到此错误消息。我的package.json(我添加了我的homepage链接、predeploy和deploy脚本,以及gh-页面依赖):"name":"test-deploy","version":"0.1.0","private":true,"homepage":"https://vnsteven.github.io/te