mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-01-30 13:37:35 +00:00
google-protobuf: adjust Message.clone[Message]() (#38476)
Returning [the polymorphic `this` type](https://www.typescriptlang.org/docs/handbook/advanced-types.html#polymorphic-this-types) ensures calling `.clone()` or `.cloneMessage()` on a subclass instance doesn't require a redundant cast.
This commit is contained in:
parent
f966375bc7
commit
9d29625c8e
@ -534,3 +534,8 @@ class MySimple extends jspb.Message {
|
||||
return jspb.Message.getField(this, 15) != null;
|
||||
}
|
||||
};
|
||||
|
||||
// ensures messages are cloneable without a redundant cast
|
||||
const myMessage: MySimple = new MySimple();
|
||||
const myClonedMessage: MySimple = myMessage.clone();
|
||||
const myClonedMessage2: MySimple = myMessage.cloneMessage()
|
||||
|
||||
5
types/google-protobuf/index.d.ts
vendored
5
types/google-protobuf/index.d.ts
vendored
@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/google/google-protobuf
|
||||
// Definitions by: Marcus Longmuir <https://github.com/marcuslongmuir>
|
||||
// Chaitanya Kamatham <https://github.com/kamthamc>
|
||||
// Austin Bonander <https://github.com/abonander>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
type ByteSource = ArrayBuffer | Uint8Array | number[] | string;
|
||||
@ -110,8 +111,8 @@ export abstract class Message {
|
||||
static equals(m1: Message, m2: Message): boolean;
|
||||
static compareExtensions(extension1: {}, extension2: {}): boolean;
|
||||
static compareFields(field1: any, field2: any): boolean;
|
||||
cloneMessage(): Message;
|
||||
clone(): Message;
|
||||
cloneMessage(): this;
|
||||
clone(): this;
|
||||
static clone<T extends Message>(msg: T): T;
|
||||
static cloneMessage<T extends Message>(msg: T): T;
|
||||
static copyInto(fromMessage: Message, toMessage: Message): void;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user