Q:

TypeScript - A function that returns a portion of the input

I'm new to Typescript and I want to write a function that returns the object it receives but with less info.
Let's say I have a Type like that:

type movie = {id: number, title:string, url:string, rating:number}

so I need a function that will receive an array of movies and return it only with id and title.
so if the input is:

[{id:1, title:Wonder Woman, url: www, rating:5},{id:2, title: Super
  Man, url:www2, rating:7}]

I need the output to be like that:

[{id:1, title:Wonder Woman},{id:2, title: Super Man}]

Is there an easy way to do that?

A:

You can signal to TS that you're working with part of a type (called a Partial) by using Partial<...>
type Movie = { id: string | number, name: string, url: string }

const movies: Movie[] = [
  { id: 1, name: "Movie A", url: "http://www.google.com" },
  { id: 2, name: "Movie B", url: "http://www.google.com" }
]

function stripUrl ({ id, name }: Movie): Partial<Movie> {
  return { id, name }
}

const mMovies = movies.map(stripUrl)

