Filter Out Unneeded Object Properties For Interface In Typescript
As background, I'm using Prisma (graphql), mysql2 (nodejs) and typescript. I'm using an interactive command line script to connect to mysql2. This is the warning I am seeing: Ign
Solution 1:
Not sure if there's a specific TypeScript way to deal with this, but you can use destructuring/spread for this:
const { type, ...validCredentials } = credentials;
This essentially picks type
out of credentials, and validCredentials
will contain the rest of the properties.
The reason .filter
didn't work is because filter is a prototype method on arrays, not objects.
Solution 2:
If you insist on using Array methods, .map()
is probably most helpful:
let obj2big = { a: 1, b: 2, c: 3 }
// let's assume what you want from this is { a: 1, c: 3 }let arr = [obj2big]
let result = arr.map(i=>({a:i.a, c: i.c}))
console.log(result[0])
Post a Comment for "Filter Out Unneeded Object Properties For Interface In Typescript"