'How to skip a 'Partial<Interface>' property based on a ternary operation result
I have a TypeScript interface that I am using to create an object of. In my case, I am only partially implementing the interface since not all the property are always available.
One of the property I want to populate is based on whether I have a certain value or not from a MongoDB query.
const Person {
name: string,
age: number
}
...
const newPerson : Partial<Person> = {
name: result.name,
age: result.age ? result.age : // skip property
}
Is there a way I can achieve this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
