avalanche1
avalanche1

Reputation: 3592

Flow - how to use declared type in another type?

import type {crusherDowntimeRecord} from "./downtime/types";

type Props = {
  data: Array<crusherDowntimeRecord>,
};
type State = {
  rows: Props.data,
};

On Props.data Flow throws:

Error:(30, 15) Cannot get Props.data because property data is missing in Props [1].

What's wrong?

Upvotes: 1

Views: 74

Answers (1)

Marko Savic
Marko Savic

Reputation: 2394

You can't access data through Props because it's type, not javascript object. For solution use flow $PropertyType:

import type {CrusherDowntimeRecord} from "./downtime/types";

type Props = {
  data: Array<CrusherDowntimeRecord>,
};

type State = {
  rows: $PropertyType<Props, 'data'>,
};

Flow - Property type

FlowTry - Example

Upvotes: 1

Related Questions