<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gabriel Levi on Medium]]></title>
        <description><![CDATA[Stories by Gabriel Levi on Medium]]></description>
        <link>https://medium.com/@gabelevi?source=rss-358d194b85e7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Cn26upIBSybgFU8t.jpg</url>
            <title>Stories by Gabriel Levi on Medium</title>
            <link>https://medium.com/@gabelevi?source=rss-358d194b85e7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:04:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gabelevi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Live Flow errors in your IDE]]></title>
            <link>https://medium.com/flow-type/live-flow-errors-in-your-ide-bcbeda0b316?source=rss-358d194b85e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcbeda0b316</guid>
            <category><![CDATA[flow]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[flowtype]]></category>
            <dc:creator><![CDATA[Gabriel Levi]]></dc:creator>
            <pubDate>Fri, 25 Oct 2019 16:14:12 GMT</pubDate>
            <atom:updated>2019-10-25T16:14:12.218Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GtjDZpmQWBnVw3tI" /><figcaption>Photo by <a href="https://unsplash.com/@cadop?utm_source=medium&amp;utm_medium=referral">Mathew Schwartz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The Flow team has been working hard to make Flow even faster at rechecking your code after you make changes. To supplement that work, here is a new feature that just makes Flow <em>feel</em> faster!</p><p>As of v0.110.1, Flow can now show you live errors as you type in your IDE, assuming your IDE’s Flow plugin uses the Flow language server via flow lsp.</p><h3>Old behavior</h3><p>Flow would show parse errors as you type, but not type errors. We would only show type errors after you save. Changing a file too much could even cause the errors to disappear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*nivnJSA6fZvFRVSxVn0RpQ.gif" /><figcaption>Demo of the old behavior</figcaption></figure><h3>New behavior</h3><p>As you type, Flow will typecheck the file that you are modifying and send back the errors near instantly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*J64bXNR_PorTRPlsnur82Q.gif" /><figcaption>Demo of the new behavior</figcaption></figure><h3>How this works</h3><ol><li>As you type, your IDE sends onChange notifications to Flow’s language server.</li><li>The Flow server uses these onChange notifications to build a copy of your modified file.</li><li>The Flow server looks up the types for all the imports in your modified file.</li><li>The Flow server typechecks your modified file and sends back the errors. This works even during rechecks, <a href="https://medium.com/flow-type/a-more-responsive-flow-1a8cb01aec11">thanks to some prior work</a>!</li><li>If files change on disk and you have open files in your IDE (e.g. maybe you rebased or saved one file), then Flow rechecks all the open files quickly.</li></ol><h3>Caveats</h3><ul><li>You won’t see live errors until the Flow server starts up and checks the imports of your file.</li><li>Flow uses the saved-to-disk versions of all imports to check your modified files. If A.js imports from B.js, then the live errors for A.js will always use the saved-to-disk version of B.js. If you change B.js, you will need to save it before the live errors for A.js reflect the changes.</li><li>Flow only shows live errors for open files. You need to save in order to see errors in downstream files. For example if you delete an export, you won’t see live errors for the files which import that export until you save. If the modified file is in a cycle, then it is technically downstream from itself. So if you make changes to A.js that would normally propagate through the cycle and affect A.js again, then the live errors won’t reflect that propagation.</li></ul><h3>Let us know if you find any issues!</h3><p>Ideally your IDE should show the same errors for a modified file that it would show if you saved it and ran flow status or flow check. If you see any discrepancies, we’d love to know! Please <a href="https://github.com/facebook/flow/issues">open a github issue</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcbeda0b316" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flow-type/live-flow-errors-in-your-ide-bcbeda0b316">Live Flow errors in your IDE</a> was originally published in <a href="https://medium.com/flow-type">Flow</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A more responsive Flow]]></title>
            <link>https://medium.com/flow-type/a-more-responsive-flow-1a8cb01aec11?source=rss-358d194b85e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a8cb01aec11</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Gabriel Levi]]></dc:creator>
            <pubDate>Fri, 08 Feb 2019 14:36:31 GMT</pubDate>
            <atom:updated>2019-02-08T14:36:31.540Z</atom:updated>
            <content:encoded><![CDATA[<p>Flow v0.92 responds to requests during rechecks</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7hHejpl4EeMxhfa9" /><figcaption>Photo by <a href="https://unsplash.com/@mrbrodeur?utm_source=medium&amp;utm_medium=referral">Matthew Brodeur</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When editing Flow code in an IDE, users expect features like autocompletion and jump-to-definition to work. However, the Flow support for these features often stops working temporarily after saving or rebasing. Flow v0.92 addresses this poor user experience.</p><h3>The problem</h3><p>Commands like flow autocomplete and flow get-def (and their <a href="https://langserver.org/">LSP</a> counterparts textDocument/completion and textDocument/definition) are already typically very fast for the Flow server to run. If you need autocompletion in the file foo.js, Flow will just quickly typecheck your local foo.js buffer (in case you made changes) and return the suggestions. This typechecking usually takes the server tens of milliseconds to run, since a running Flow server has already computed the types of all the imported modules.</p><p>So if running these commands is so fast, why was Flow so slow at responding to many of these commands?</p><p>It was because the Flow server was often busy rechecking the codebase. When you save a file, Flow notices the change and starts updating its type information. Flow could not respond to commands like flow autocomplete until the recheck had finished for two main reasons:</p><ol><li>Commands like flow autocomplete need the type information for all the imported modules. But rechecks happen because Flow needs to recompute type information, so during a recheck we won’t necessarily have up-to-date type information. Without up-to-date type information, Flow might answer some commands incorrectly.</li><li>The Flow server wasn’t architected to do more than one thing at once. Flow was single threaded and sloppy with how it read and wrote state.</li></ol><h3>The solution</h3><p>We addressed reason #1 by using out-of-date type information. We can just use type information from before the recheck to respond to requests. While using out-of-date information could lead to commands like flow autocomplete returning incorrect results, it is relatively rare and a price worth paying for the responsiveness.</p><p>We addressed reason #2 with a year-long re-architecture of Flow server’s internals. We are now more rigorous with how we read and write state and have heavily integrated with the fantastic <a href="https://github.com/ocsigen/lwt">Lwt library</a>, a cooperative threading library for OCaml.</p><h3>Try it out!</h3><p>Starting in v0.92.1, Flow now responds to many CLI and LSP commands immediately, without waiting for the recheck to finish. At Facebook, we’re seeing a big drop in response times for Flow requests send from our IDEs. textDocument/completion&#39;s average response time has dropped ~75% and the p90 response time has dropped ~95%. Hopefully this change will improve your experience with Flow too!</p><p>If this causes any trouble for you, you can disable this behavior in the .flowconfig with</p><pre>[options]<br>wait_for_recheck=true</pre><p>or for an individual CLI command with the --wait-for-recheck true option.</p><p>Hope this helps! Enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a8cb01aec11" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flow-type/a-more-responsive-flow-1a8cb01aec11">A more responsive Flow</a> was originally published in <a href="https://medium.com/flow-type">Flow</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New Flow Errors on Unknown Property Access in Conditionals]]></title>
            <link>https://medium.com/flow-type/new-flow-errors-on-unknown-property-access-in-conditionals-461da66ea10?source=rss-358d194b85e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/461da66ea10</guid>
            <category><![CDATA[flowtype]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Gabriel Levi]]></dc:creator>
            <pubDate>Fri, 16 Mar 2018 15:02:41 GMT</pubDate>
            <atom:updated>2018-03-16T15:02:41.816Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rsAM7uP-3HcYfIM_0YdFiQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/qpZFTRM-Bec?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jason Yu</a> on <a href="https://unsplash.com/search/photos/error?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>TL;DR: Starting in 0.68.0, Flow will now error when you access unknown properties in conditionals.</p><h3>Flow already disallows accessing unknown properties outside of conditionals</h3><p>Let’s say I want to write a function that takes a person object and returns the name of that person’s dog. If that person doesn’t have a dog, it will return undefined:</p><pre>function getNameOfDog(person: { age: number }): void | string {<br>  return person.nameOfDog;<br>}</pre><p>If the object person doesn’t have a property nameOfDog, then the expression person.nameOfDog will evaluate to undefined. So this code does work as expected. However, Flow 0.67.1 will produce the following error.</p><pre>2:   return person.nameOfDog;<br>                   ^ Cannot get `person.nameOfDog` because property `nameOfDog` is missing in object type [1].<br>References:<br>1: function getNameOfDog(person: { age: number }): void | string {<br>                                 ^ [1]</pre><p>We require our users to annotate what properties might exist. The following would produce no Flow errors:</p><pre>function getNameOfDog(<br>  person: { age: number, nameOfDog?: string },<br>): void | string {<br>  return person.nameOfDog;<br>}</pre><p>Why does Flow disallow this valid JavaScript pattern? It is because we found that spelling mistakes in property names are a very common source of bugs in JavaScript. By banning accessing unknown properties, we can catch errors like this:</p><pre>function getNameOfDog(<br>  person: { age: number, nameOfDog?: string },<br>): void | string {<br>  return person.nameofdog; // Wrong capitalization!<br>}</pre><h3>Existence testing in conditionals</h3><p>However, until 0.68.0, Flow would allow you to test the existence of unknown properties in conditionals. So Flow would allow you to write</p><pre>function reportDogOwnerToPolice(person: { age: number }): void {<br>  if (person.hasDog) { callPolice(); }<br>}</pre><p>and if you accidentally wrote</p><pre>if (person.hasDoge) { callPolice(); }</pre><p>Flow would miss your spelling mistake.</p><p>If you tested whether an unknown property existed, Flow would refine that unknown property to mixed. So you could write</p><pre>function getNameOfDog(person: { age: number }): mixed {<br>  return person.dog &amp;&amp; person.dog.name ? person.dog.name : null;<br>}</pre><p>and Flow would infer that,</p><ul><li>if person.dog exists, it has the type mixed.</li><li>If person.dog.name exists, it has the type mixed.</li></ul><p>But again, Flow would fail to point out spelling mistakes. And furthermore, Flow would allow code that was trivially incorrect, like accessing imaginary properties on Number.prototype!</p><pre>function abs(x: number): number {<br>  return x.isNegative ? x * -1 : x;<br>}</pre><h3>We‘ve changed this behavior!</h3><p>Now accessing unknown properties in conditionals behaves like accessing them outside of conditionals.</p><pre>function abs(x: number): number {<br>  return x.isNegative ? x * -1 : x;<br>}</pre><p>produces the error</p><pre>2:   return x.isNegative ? x * -1 : x;<br>            ^ property `isNegative` is missing in number [1].<br>References:<br>1: function abs(x: number): number {<br>                   ^ [1]</pre><p>and</p><pre>function getNameOfDog(person: { age: number }): mixed {<br>  return person.dog &amp;&amp; person.dog.name ? person.dog.name : null;<br>}</pre><p>produces the error</p><pre>2:   return person.dog &amp;&amp; person.dog.name ? person.dog.name : null;<br>            ^ property `dog` is missing in object type [1].<br>References:<br>1: function getNameOfDog(person: { age: number }): mixed {<br>                                 ^ [1]</pre><p>To fix that second example to work with Flow 0.68.0, I would change it to</p><pre>function getNameOfDog(<br>  person: { age: number, dog?: { name?: string} },<br>): string | null {<br>  return person.dog &amp;&amp; person.dog.name ? person.dog.name : null;<br>}</pre><h3>Union types</h3><p>You can test the existence of a property which exists in some branch of the union inside the conditional. With Flow 0.68.0, the following code</p><pre>function nameOfPet(<br>  pet: {|catName: string|} | {|dogName: string|}<br>): string | void {<br>  if (pet.catName) { return pet.catName; }<br>  if (pet.dogName) { return pet.dogName; }<br>  if (pet.zebraName) { return pet.zebraName; }<br>}</pre><p>produces the error</p><pre>6:   if (pet.zebraName) { return pet.zebraName; }<br>         ^ property `zebraName` is missing in object type [1].<br>References:<br>2:   pet: {|catName: string|} | {|dogName: string|}<br>          ^ [1]</pre><p>Accessing catName and dogName are allowed, because they each appear in the union. But accessing zebraName is disallowed because it doesn’t appear anywhere.</p><h3>Classes</h3><p>Before Flow 0.68.0, the following would have produced no errors</p><pre>class Animal {}<br>class Dog extends Animal { name: string }<br>class UnnameableBeast extends Animal {}</pre><pre>function nameOfPet(pet: Animal): mixed {<br>  if (pet.name) { return pet.name; }<br>}</pre><p>But in Flow 0.68.0, you’ll get the error</p><pre>6:   if (pet.name) { return pet.name; }<br>         ^ property `name` is missing in `Animal` [1].<br>References:<br>5: function nameOfPet(pet: Animal): mixed {<br>                           ^ [1]</pre><p>The fix is to either declare name in Animal.</p><pre>class Animal { +name: string | void }<br>class Dog extends Animal { name: string }<br>class UnnameableBeast extends Animal {}</pre><pre>function nameOfPet(pet: Animal): mixed {<br>  if (pet.name) { return pet.name; }<br>}</pre><p>Or to use instanceof</p><pre>class Animal {}<br>class Dog extends Animal { name: string }<br>class UnnameableBeast extends Animal {}</pre><pre>function nameOfPet(pet: Animal): mixed {<br>  if (pet instanceof Dog) { return pet.name; }<br>}</pre><h3>Feedback welcome!</h3><p>We made this change after receiving a lot of feedback about Flow missing spelling mistakes in property names. Love this new behavior? Hate this new behavior? Let us know!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=461da66ea10" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flow-type/new-flow-errors-on-unknown-property-access-in-conditionals-461da66ea10">New Flow Errors on Unknown Property Access in Conditionals</a> was originally published in <a href="https://medium.com/flow-type">Flow</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>