TR Output

フロントエンドエンジニアの備忘録

【TypeScript】型をすべてオプショナルに変換する

type SampleType = {
  id: number;
  name: string;
}
// 1
type OptionalSampleType1 = Partial<SampleType>;
// 2
type OptionalSampleType2 = {
  [K in keyof SampleType]?: SampleType[K];
}