Skip to content

Commit

Permalink
Use object type spreads instead of intersections
Browse files Browse the repository at this point in the history
The previous code is wrong because an object can't simultaneously
satisfy two distinct, exact object types.

The correct way is using object type spreads as described here:
facebook/flow#2626

I'm not sure why things currently type-check.
  • Loading branch information
mwiencek committed Mar 17, 2018
1 parent 74408df commit e371bb1
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 158 deletions.
2 changes: 1 addition & 1 deletion root/components/Aliases/AliasTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {l} = require('../../static/scripts/common/i18n');
type Props = {
+aliases: $ReadOnlyArray<AliasT>,
+allowEditing: boolean,
+entity: $Subtype<CoreEntityT>,
+entity: CoreEntityT,
};

const AliasTable = (props: Props) => (
Expand Down
2 changes: 1 addition & 1 deletion root/components/EntityHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SubHeader = require('./SubHeader');

type Props = {|
+editTab?: React.Node,
+entity: $Subtype<CoreEntityT>,
+entity: CoreEntityT,
+headerClass: string,
+heading?: string | React.Node,
+page: string,
Expand Down
2 changes: 1 addition & 1 deletion root/components/EntityTabLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const EntityLink = require('../static/scripts/common/components/EntityLink');

type Props = {|
+content: string,
+entity: EntityT,
+entity: CoreEntityT,
+selected: boolean,
+subPath: string,
|};
Expand Down
4 changes: 2 additions & 2 deletions root/components/EntityTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const buildLink = (
);

function buildLinks(
entity: $Subtype<EntityT>,
entity: CoreEntityT,
page: string,
editTab: React.Node,
hideEditTab: boolean,
Expand Down Expand Up @@ -91,7 +91,7 @@ function buildLinks(

type Props = {|
+editTab: React.Node,
+entity: EntityT,
+entity: CoreEntityT,
+hideEditTab?: boolean,
+page: string,
|};
Expand Down
1 change: 1 addition & 0 deletions root/static/scripts/common/components/CodeLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const CodeLink = ({code}: Props) => {
let link = (
<a href={entityHref(code)}>
<bdi>
{/* $FlowFixMe */}
<code>{code[code.entityType]}</code>
</bdi>
</a>
Expand Down
7 changes: 6 additions & 1 deletion root/static/scripts/common/utility/entityHref.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ const nonEmpty = require('./nonEmpty');

const leadingSlash = /^\/?(.*)/;

type LinkableEntity =
| CoreEntityT
| IsrcT
| IswcT;

function entityHref(
entity: EntityT | CoreEntityT,
entity: LinkableEntity,
subPath?: string,
) {
const entityType = entity.entityType;
Expand Down
Loading

0 comments on commit e371bb1

Please sign in to comment.