Reputation: 106
I have an Interface Data
which is structured like this:
interface Data {
message: string;
Id: string;
uid: string;
}
Data with this Structure uploads to a database.
When I want to Update one Element on my database I call a function updateData(updatedData)
and I want this variable updatedData
to be an Object not of type Data
but all properties should be part of the Datainterface.
I tried to find an answer to this question but I don‘t even know how to express my question in a short way so I can get some good results from a search engine.
So maybe you can give me at least a keyword to search.
Upvotes: 0
Views: 37
Reputation: 2878
if i understand you correctly you just want partial of Data interface? if so, you can use partial type in ts.
interface IData {
message: string;
id: string;
uid: string;
}
type partialData = Partial<IData>;
const messageData: partialData = {
message: 'only message updated',
};
const idData: partialData = {
id: 'only id updated',
};
const updateData = (data: partialData) => {
console.log();
};
updateData(messageData);
updateData(idData);
from ts definition
type Partial<T> = { [P in keyof T]?: T[P] | undefined; }
it just make all properties as optional
Upvotes: 1