Missak Boyajian
Missak Boyajian

Reputation: 2245

Typescript share property types

In typescript I have this interface.

export interface FlexProps {
  justifyContent:
  | "initial"
  | "center"
  | "flex-start"
  | "flex-end"
  | "space-between"
  | "space-around";

  alignItems:
  | "initial"
  | "center"
  | "stretch"
  | "flex-start"
  | "flex-end"
  | "baseline";
}

Is there a way I can transform this into?

    const shared: "initial" | "center" | "flex-start" | "flex-end"

    export interface FlexProps {
      justifyContent: shared | "space-between" | "space-around";
      alignItems: shared | "stretch" | "baseline";
    }

Upvotes: 0

Views: 56

Answers (1)

Wing
Wing

Reputation: 9701

You may have made a typo when declaring your shared types. You have used const but it should be type:

-  const shared: "initial" | "center" | "flex-start" | "flex-end"
+  type shared = "initial" | "center" | "flex-start" | "flex-end";

   export interface FlexProps {
     justifyContent: shared | "space-between" | "space-around";
     alignItems: shared | "stretch" | "baseline";
   }

Here is a demo:

type shared = "initial" | "center" | "flex-start" | "flex-end";

interface FlexProps {
    justifyContent: shared | "space-between" | "space-around";
    alignItems: shared | "stretch" | "baseline";
}

Upvotes: 2

Related Questions