Created
March 6, 2018 14:28
-
-
Save dmeehan1968/b2a64f5a73e7e59c419c2c9680b11396 to your computer and use it in GitHub Desktop.
Exploring Flow's 'missing indexer property' on class computed properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @flow */ | |
type KeyType = string | |
type ValueType = any | |
type MyMap = { | |
[KeyType]: ValueType | |
} | |
const object: MyMap = { | |
'foo': 'bar', | |
} | |
object['foo'] = 'baz' | |
object.foo = 'bork' | |
declare class A { | |
[KeyType]: ValueType | |
} | |
const a: A = new A | |
a['foo'] = 'bar' | |
declare interface IMap { | |
[KeyType]: ValueType | |
} | |
// eslint: Parsing error: Unexpected token, expected "{" (Fatal) (@ 'implements') | |
declare class B /*:: implements IMap */ { | |
[KeyType]: ValueType | |
} | |
// fix eslint | |
declare class B /*:: implements IMap*/ { | |
[KeyType]: ValueType | |
} | |
const b: B = new B | |
b['foo'] = 'bar' | |
b.foo = 'bork' // flow: Cannot assign `'bork'` to `b.foo` because property `foo` is missing in `B` [1]. | |
declare class C /*:: implements IMap*/ { | |
[KeyType]: ValueType, | |
foo: string, | |
hello: () => void, | |
} | |
const c: C = new C | |
c['foo'] = 'bar' | |
c.foo = 'bork' | |
c.hello() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment