I'm working on a Typescript project where I need to pass the same object between multiple functions with different interfaces.
These are the interfaces:
export interface TestModel {
fileName:string,
year:number,
country:string
}
export interface Test2Model {
fileName:string,
year:number
}
This is the initial function that generates the object and calls another function by passing the generated object:
function generateObject() {
let fileData:TestModel = {
fileName:'fileName',
year:2022,
country:'Spain'
}
processObject(fileData)
}
generateObject();
This is the second processing function:
function processObject(fileData:Test2Model) {
console.log(fileData)
}
The output in the processing function looks like this:
{fileName: "fileName", year: 2022, country: "Spain"}
However, I actually want the output to be:
{fileName: "fileName", year: 2022}
My challenge: Is there a way to automatically adjust the object to match the Test2Model interface without creating an entirely new object?