How do I create an object that is compatible with the Timestamp type in protobuf.js in TypeScript?

415 Views Asked by At

When I try to assign to a Timestamp field of a protocol buffer built with protobuf.js, I get a TypeScript error.

My protocol buffer has the following definition:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

message MyMessage {
    Timestamp expires_at = 1;
}

My Typescript file is the following:

import { MyMessage } from ...
import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb.js'

export const myFunction() {
    let myMessage = new MyMessage()
    myMessage.expiresAt = new Timestamp()
}

I get an error messsage that says: Type 'Timestamp' has no properties in common with type 'ITimestamp'

What's going on here? What is ITimestamp? How do I create an object that is compatible with the Timestamp type in protobuf.js?

0

There are 0 best solutions below