Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dmeehan1968/b2a64f5a73e7e59c419c2c9680b11396 to your computer and use it in GitHub Desktop.
Save dmeehan1968/b2a64f5a73e7e59c419c2c9680b11396 to your computer and use it in GitHub Desktop.
Exploring Flow's 'missing indexer property' on class computed properties
/* @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