Can't assign {p:null} to interface with shape {p: ?T}
Here is what I'm trying to do:
/* @flow */
interface Selections {
selected: any;
lastSelectedId: ?string;
}
let DEFAULT_SELECTIONS: Selections = {
selected: {},
lastSelectedId: null
}
But get an error:
/Users/xesued/testbed/flow/src/index.js:4:19,24: string
This type is incompatible with
/Users/xesued/testbed/flow/src/index.js:9:18,21: null
/Users/xesued/testbed/flow/src/index.js:4:19,24: undefined
This type is incompatible with
/Users/xesued/testbed/flow/src/index.js:9:18,21: null
If I use a type alias it works. If I make it non-nullable and assign the correct type it works as well.
Thanks! Looks like a real bug. This works for object type aliases, but it seems like it doesn't just for interfaces.
So is this definitely a bug or is this a choice made by design? When reading the interface docs, it seems to mention optional properties here, but it doesn't say anything about nullable types. I wasn't sure if this meant that interfaces weren't allowed to have nullable types or if the docs just didn't include info on it.
Looks like this works now.