Reputation: 601
In this piece of code, flow is not complaining about the value dog
being set on the state. It seems to be ignoring the NamespaceData
definition. I've set up the types so it should complain. I'm running on nuclide and flow is working properly for everything else.
All of the properties of action
such as namespace
, project
, collection
are strings.
// @flow
import { NAMESPACE_SET } from '../actions/NamespaceActions'
type NamespaceData = {
project: string,
collection: string,
}
type NamespaceState = {
[namespace: string]: NamespaceData,
}
const initialState: NamespaceState = {}
function namespaceReducer(state: NamespaceState = initialState, action: Object): NamespaceState {
switch (action) {
case NAMESPACE_SET: {
return {
...state,
[action.namespace]: {
project: action.project,
collection: action.collection,
dog: 1,
}
}
}
}
return state
}
export default namespaceReducer
Upvotes: 6
Views: 141
Reputation: 161477
Flow is not strict about unknown properties in objects by default, e.g.
// @flow
type Thing = {
known: string;
};
var obj: Thing = {
known: 'hi',
unknown: 4,
};
typechecks fine even though unknown
is not in the type.
Flow 0.32 includes
In your example you'd want exact object syntax with:
type NamespaceData = {|
project: string,
collection: string,
|};
Upvotes: 7