Tomasz Mularczyk
Tomasz Mularczyk

Reputation: 36179

Flow - type a variable with global type property type

I have a global type in flow-typed directory like this:

import type { UI, User, Projects, Profile } from 'data/redux/redux.flow';

declare type State = {
  +ui: UI,
  +user: User,
  +projects: Projects,
  +profile: Profile,
}

each property has its own type imported from data/redux/redux.flow.js file.

I wonder is it possible now to do something like below somewhere in my app:

type Props = {
  profile: State.profile, //or maybe State$Profile e.t.c
}

so basically I dont have to make Profile type global also.

?

Upvotes: 2

Views: 1074

Answers (1)

adrice727
adrice727

Reputation: 1492

Yes. You can use $PropertyType:

type Props = {
  profile: $PropertyType<State, 'profile'>
}

Flow Utility Types - Property Type

Possible Bug with PropertyType

Upvotes: 3

Related Questions