Do I have to use question mark or Partial utility type to make a field optional using TypeScript

26 Views Asked by At

I create below TypeScript types:

import { MyType, SectionTheme } from 'app/store/types';

export type Props = {
  data: MyType;
} & SectionTheme;

export type StylesProps = ThemeProps & Pick<Props, 'theme'>;

How do I make theme optional?

Do I have to go to SectionTheme type and add ? like:

export type SectionTheme = {
  theme?: 'one' | 'two';
};

Or do I have to use utility Partial type? And how exactly. What's the difference and what is better to use in my case?

0

There are 0 best solutions below