22
loading...
This website collects cookies to deliver better user experience
"TypeScript isn't useful because it doesn't do runtime type checking"
const add = (value2: number) => (value1: number) => value1 + value2;
fetch("https://swapi.dev/api/people/1")
.then(response => response.json())
.then(({ name }: People) => console.log(`Hello ${name}`))
.catch(console.error);
People
and maybe we got something else from the API. In those scenarios you have several options, one is to use something like Partial
which makes all the properties of an object optional, so TS will tell you that name
could be undefined:.then(({ name }: Partial<People>) =>
typeof name === "string"
? console.log(`Hello ${name}`)
: Promise.reject("Response is not of type People")
);
"TypeScript isn't useful because it doesn't do something it wasn't designed to do in the first place"