Always provide explicit default values for configuration options to improve code readability and maintainability. Use helper methods consistently for default value management, and document defaults clearly.
When setting configuration options:
getOptionsProp()
with explicit default values:
```typescript
// Good - default value is explicit
this.port = this.getOptionsProp(options, ‘port’, TCP_DEFAULT_PORT);
this.rawOutputPackets = this.getOptionsProp(options, ‘rawOutputPackets’, false);// Avoid - implicit default through || operator this.port = this.getOptionsProp(options, ‘port’) || TCP_DEFAULT_PORT;
2. Conditionally add configuration options only when needed:
```typescript
// Good - only add config when value exists
const serverOptions = {
...this.maxSendMessageLength ?
{ 'grpc.max_send_message_length': this.maxSendMessageLength } :
{}
};
// Avoid - setting undefined values
const serverOptions = {
'grpc.max_send_message_length': this.maxSendMessageLength
};
// When defaults differ between contexts (e.g., client vs server): /**
"-server"
on server side and "-client"
on client side.
*/
clientId?: string;
```Following these practices makes configuration behavior more predictable and self-documenting, reduces bugs from unexpected undefined values, and makes code easier to maintain.
Enter the URL of a public GitHub repository