L
L
lexstile2020-05-31 20:40:15
typescript
lexstile, 2020-05-31 20:40:15

How to write types correctly?

Initially it was like this:

export enum SelectSize {
    medium = 'medium',
    large = 'large',
}
export const selectSizeValues: { [key in SelectSize]: string } = {
    [SelectSize.medium]: '24px 56px 8px 16px',
    [SelectSize.large]: '32px 64px 8px 24px',
};

I want to do like this:
export enum SelectSize {
    medium = 'medium',
    large = 'large',
}
export enum SelectSize1 {
    bottom = 'bottom',
    left = 'left',
    right = 'right',
    top = 'top',
}
export const selectSizeValues: { [key in SelectSize]: /* Какой тип прописать тут? */ } = {
    [SelectSize.medium]: {
        bottom: '8px',
        left: '16px',
        right: '56px',
        top: '24px',
    },
    [SelectSize.large]: {
        bottom: '8px',
        left: '24px',
        right: '64px',
        top: '32px',
    },
};

How to write styles for the latter?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GF, 2020-05-31
@lexstile

export enum SelectSize {
  medium = "medium",
  large = "large",
}

// создай тип
type PositionProps = {
  bottom: string;
  left: string;
  right: string;
  top: string;
};

// или интерфейс
interface PositionProps {
  bottom: string;
  left: string;
  right: string;
  top: string;
};

export const selectSizeValues: { [key in SelectSize]: PositionProps } = {
  [SelectSize.medium]: {
    bottom: "8px",
    left: "16px",
    right: "56px",
    top: "24px",
  },
  [SelectSize.large]: {
    bottom: "8px",
    left: "24px",
    right: "64px",
    top: "32px",
  },
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question