enter code here
I have a property which is of type any right now. It calls a function which then returns 2 strings in an object.
let datesByMSId: any = await this.entrybyMSId(msId)
The log turns out to look the following.
{
start: '2022-07-20T00:00:00.0000000',
end: '2022-07-21T00:00:00.0000000'
}
I tried to define an interface DeleteVacationPayload which looks like this:
export interface DeleteVacationPayload
{
start: string,
end: string
}
When I implement the interface, i get this error:
Type '{}' is missing the following properties from type 'DeleteVacationPayload': start, end
Here is a snippet of the entrybyMSId function:
request(options, async function (error, response, body) {
if (!error) {
let parsedBody = JSON.parse(body)
let values:Dates = {
start: parsedBody.start.dateTime,
end: parsedBody.end.dateTime
}
resolve(values)
}
}
I don't really understand why I get this error.
You need to use semicolons when defining the interface.
Try this:
export interface DeleteVacationPayload {
start: string;
end: string;
}
More info about interfaces with Typescript here: https://www.typescriptlang.org/docs/handbook/interfaces.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.