javascript - Is there something like incomplete (partial) declarations for Flow? -


i'd incrementally add declarations external library. possible write declaration describes properties of object/interface , remaining properties omitted declaration , unchecked?

for example: can following object

const = {foo: 8, bar: 9} 

have declaration describing 1 property?

declare var a: any|{foo: number} // doesn't work 

the intended behavior if property found in declaration type enforced. type of non-mentioned properties considered any.


typescript solves problem using properties expression:

interface iface {     foo: number;     [propname: string]: any; } 

type partiala = {foo:number, [key:string]: any} const a: partiala = {foo: 1, bar: 2} console.log(a.bar) 

this options safer following 1 since types of known properties onforced:

a.foo = 'a' // causes error // 6: a.foo = 'a' //            ^ string. type incompatible // 3: type partiala = {foo:number, [key:string]: any} //                         ^ number 

or

type partialb = {foo:number}&any const b: partialb = {foo: 1, bar: 2} console.log(b.bar) b.foo = 'a' // ok in flow 

tested flow v0.34.0

credit: @loganfsmyth, @gcanti


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -