Skip to content

Commit de18bbe

Browse files
authored
docs: Document custom constructor registration order (#2323)
1 parent c98a4e5 commit de18bbe

3 files changed

Lines changed: 3 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ const decoded = AwesomeMessage.decode(bytes);
292292
decoded.customInstanceMethod(); // string
293293
```
294294

295-
protobuf.js will populate the constructor with the usual static runtime methods and use it for decoded messages. In TypeScript, custom members are visible when using the custom class type in consuming code.
295+
protobuf.js will populate the constructor with the usual static runtime methods and use it for decoded messages. When assigning constructors manually, add the type to its parent namespace/root first if fields reference other reflected types. In TypeScript, custom members are visible when using the custom class type in consuming code.
296296

297297
### Services
298298

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,7 @@ export class Type extends NamespaceBase {
17161716
/**
17171717
* The registered constructor, if any registered, otherwise a generic constructor.
17181718
* Assigning a function replaces the internal constructor. If the function does not extend {@link Message} yet, its prototype will be setup accordingly and static methods will be populated. If it already extends {@link Message}, it will just replace the internal constructor.
1719+
* When assigning manually, add the type to its parent namespace/root first if fields reference other reflected types, because constructor setup resolves field defaults.
17191720
*/
17201721
ctor: Constructor<{}>;
17211722

src/type.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Object.defineProperties(Type.prototype, {
155155
/**
156156
* The registered constructor, if any registered, otherwise a generic constructor.
157157
* Assigning a function replaces the internal constructor. If the function does not extend {@link Message} yet, its prototype will be setup accordingly and static methods will be populated. If it already extends {@link Message}, it will just replace the internal constructor.
158+
* When assigning manually, add the type to its parent namespace/root first if fields reference other reflected types, because constructor setup resolves field defaults.
158159
* @name Type#ctor
159160
* @type {Constructor<{}>}
160161
*/

0 commit comments

Comments
 (0)