Typescript Utility Partial

Partial

Constructs a type with all properties of Type set to optional. This utility will return a type that represents all subsets of a given type.

example

interface Todo {
title: string;
description: string;
}

function updateTodo(…

Partial

Constructs a type with all properties of Type set to optional. This utility will return a type that represents all subsets of a given type.



example

interface Todo {
  title: string;
  description: string;
}

function updateTodo(todo: Todo, fieldsToUpdate: Partial<Todo>) {
  return { ...todo, ...fieldsToUpdate };
}

const todo1 = {
  title: "organize desk",
  description: "clear clutter",
};

const todo2 = updateTodo(todo1, {
  description: "throw out trash",
})

Released:
2.1

Reference :Typescript official docs


Print Share Comment Cite Upload Translate
APA
es404020 | Sciencx (2024-03-29T15:25:47+00:00) » Typescript Utility Partial. Retrieved from https://www.scien.cx/2021/09/08/typescript-utility-partial/.
MLA
" » Typescript Utility Partial." es404020 | Sciencx - Wednesday September 8, 2021, https://www.scien.cx/2021/09/08/typescript-utility-partial/
HARVARD
es404020 | Sciencx Wednesday September 8, 2021 » Typescript Utility Partial., viewed 2024-03-29T15:25:47+00:00,<https://www.scien.cx/2021/09/08/typescript-utility-partial/>
VANCOUVER
es404020 | Sciencx - » Typescript Utility Partial. [Internet]. [Accessed 2024-03-29T15:25:47+00:00]. Available from: https://www.scien.cx/2021/09/08/typescript-utility-partial/
CHICAGO
" » Typescript Utility Partial." es404020 | Sciencx - Accessed 2024-03-29T15:25:47+00:00. https://www.scien.cx/2021/09/08/typescript-utility-partial/
IEEE
" » Typescript Utility Partial." es404020 | Sciencx [Online]. Available: https://www.scien.cx/2021/09/08/typescript-utility-partial/. [Accessed: 2024-03-29T15:25:47+00:00]
rf:citation
» Typescript Utility Partial | es404020 | Sciencx | https://www.scien.cx/2021/09/08/typescript-utility-partial/ | 2024-03-29T15:25:47+00:00
https://github.com/addpipe/simple-recorderjs-demo