Skip to content

Instantly share code, notes, and snippets.

'use strict';
const fs = require('fs');
const n = 1000;
const m = 100;
for (let i = 0; i < n; i++) {
const contents = `
/* @flow */

Having spoken extensively to users of both Flow and TypeScript, these examples are entirely contrived because they're just demos. How often do you have a function that multiplies two numbers and returns it?

Examples are contrived because they are examples. There is no point in using 100-lines long "real-life" function. It will work the same way.

And, to be fair, I have to write functions like this fairly often:

type Animal =
| { t: 'Cat' }
| { t: 'Dog' }
;
function makeSound<T: Animal>(arr: Array<T>) {
arr.forEach(animal => {
if (animal.t === 'Cat') {
console.log('meow');
} else {
@vkurchatkin
vkurchatkin / 2.js
Last active January 10, 2017 11:49
type Animal =
| { t: 'Cat' }
| { t: 'Dog' }
;
function addADog(arr: Array<Animal>) {
arr.push({ t: 'Dog' });
}
const cats: Array<{ t: 'Cat' }>= [];
@vkurchatkin
vkurchatkin / 1.js
Last active January 10, 2017 11:41
type Animal =
| { t: 'Cat' }
| { t: 'Dog' }
;
function makeSound(arr: Array<Animal>) {
for (const animal of arr) {
if (animal.t === 'Cat') {
console.log('meow');
} else {

Unsound Flow

An attempt to compile a list of examples of unsound behavior of Flow.

Class property initialization

Flow doesn't check that all class properties are initialized in constructor:

class Foo {
class WeakMap {
constructor() {
this.s = Symbol();
}
set(key, val) {
key[this.s] = val;
'use strict';
const stream = require('stream');
class A extends stream.Readable {
_read() {
}
}
class B extends stream.Writable {
I/mbgl ( 5147): {Main}[OpenGL]: GL Vendor: Vivante Corporation
I/mbgl ( 5147): {Main}[OpenGL]: GL Renderer: GC1000 core
I/mbgl ( 5147): {Main}[OpenGL]: GL Version: OpenGL ES 2.0
I/mbgl ( 5147): {Main}[OpenGL]: GL SL Version: OpenGL ES GLSL ES 1.00
I/mbgl ( 5147): {Main}[OpenGL]: GL Extensions: GL_EXT_debug_marker GL_OES_compressed_ETC1_RGB8_texture GL_OES_compressed_paletted_texture GL_OES_EGL_image GL_OES_depth24 GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_rgb8_rgba8 GL_OES_stencil1 GL_OES_stencil4 GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_depth_texture GL_OES_packed_depth_stencil GL_OES_standard_derivatives GL_OES_get_program_binary GL_EXT_texture_format_BGRA8888 GL_IMG_read_format GL_EXT_blend_minmax GL_EXT_read_format_bgra GL_EXT_multi_draw_arrays GL_APPLE_texture
I/mbgl ( 5147): {Main}[OpenGL]: GL Extensions: _format_BGRA8888 GL_APPLE_texture_max_level GL_ARM_rgba8 GL_EXT_frag_depth GL_VIV_shader_binary GL_VIV_direct_texture GL_OES_mapbuffer GL_OES_EGL_image
MAGENTA="\[\033[0;35m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[34m\]"
LIGHT_GRAY="\[\033[0;37m\]"
CYAN="\[\033[0;36m\]"
GREEN="\[\033[0;32m\]"
NORMAL="\[\033[0;0m\]"
GIT_PS1_SHOWDIRTYSTATE=true
export LS_OPTIONS='--color=auto'
export CLICOLOR='Yes'