Skip to content

Instantly share code, notes, and snippets.

@Bannerets
Last active April 19, 2019 00:23
Show Gist options
  • Save Bannerets/5cf5315595478d308266bc7ff67ae7aa to your computer and use it in GitHub Desktop.
Save Bannerets/5cf5315595478d308266bc7ff67ae7aa to your computer and use it in GitHub Desktop.
Computed object properties in Flow
/*
https://flow.org/try/#0FAFwngDgpgBA8jAvDA3jA2gcgIaYLoBcMAziAE4CWAdgOYwC+MAZKhpgEb5FUCuAtuyhkGMAPSiYAewDWMABQADLADpVXGKuUKYFYjGxUdVACZQAHkICUwYKYDGAG2xlYAN2dSicANw3vcyWVsbn5BMksxCSEySWE5c2g7EChja39A4JJyahoI8SlpPwDldhCBK0iC4HSSolJKWjyoshi4hKgklMsgA
*/
type O = { ['a']: string } & { ['b']: number } // ok (`['...']: ...` is an indexer)
declare var o: O;
;(o.a: number) // error (expected)
;(o.a: string) // ok
;(o.b: number) // ok
;(o.b: string) // error (expected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment