2

I have a type for my reducer such as:

export type Style = {
  color: string;
  (rest...)
}

export const initialState: Style = {
  color: 'blue';
  (rest...)
}

I have a component that takes in a style object and the properties are optional and simply overwrites the current state of the style. The type looks like this:

export type InputStyle = {
  color?: string;
  (rest?...)
}

So I basically have to create two duplicate types, except one has all optional properties, and one doesn't. Is there a better pattern for this? My intuition says this is not the right way.

Adam Johnston
  • 228
  • 1
  • 8

1 Answers1

1

Try using the Partial utility type - might be exactly what you're looking for:

export type Style = {
  color: string;
  (rest...)
}

export type InputStyle = Partial<Style>;