Skip to content

feat: enhance TypeScript coding style guidelines#369

Open
jasondavey wants to merge 1 commit intoaffaan-m:mainfrom
playon:update-typescript-rules
Open

feat: enhance TypeScript coding style guidelines#369
jasondavey wants to merge 1 commit intoaffaan-m:mainfrom
playon:update-typescript-rules

Conversation

@jasondavey
Copy link

@jasondavey jasondavey commented Mar 9, 2026

This pull request adds a new section on types and interfaces to the TypeScript coding style guide, and expands guidance on error handling and input validation. The updates clarify best practices for typing public APIs, distinguishing between interfaces and type aliases, avoiding the use of any, typing React props, and using JSDoc in JavaScript files. Additionally, the error handling section now demonstrates safe narrowing of unknown errors, and the input validation section shows how to infer types from Zod schemas.

Type System Best Practices:

  • Added a comprehensive "Types and Interfaces" section, covering explicit typing for public APIs, when to use interfaces vs. type aliases, avoidance of any, best practices for React props typing, and the use of JSDoc in JavaScript files. Includes code examples for each practice.

Error Handling:

  • Updated error handling guidance to recommend using async/await with try-catch, and to safely narrow unknown errors using type guards and custom error message functions. Provided improved code examples.

Input Validation:

  • Enhanced input validation section to show how to infer TypeScript types from Zod schemas, ensuring type safety and alignment between validation and types.

Summary by cubic

Enhances the TypeScript coding style guide with a new “Types and Interfaces” section, clearer error handling patterns, and zod-based input validation with inferred types. Clarifies best practices for public APIs and React props to improve consistency and safety.

  • New Features
    • Added “Types and Interfaces” guidance: explicit types for public APIs, interface vs. type alias, avoid any, React props typing, and JSDoc for .js files.
    • Updated error handling: use async/await with try-catch and safely narrow unknown errors with guards/helpers.
    • Expanded input validation: infer TypeScript types from zod schemas to keep validation and types in sync.

Written for commit d4c6449. Summary will update on new commits.

Summary by CodeRabbit

  • Documentation
    • Updated TypeScript/JavaScript coding style guide with enhanced recommendations on type annotations, interface design patterns, immutability approaches, strict error handling, and input validation best practices.

…es and best practices esp interfaces and types
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

This pull request adds a comprehensive TypeScript/JavaScript coding style guide covering explicit type annotations, interfaces vs. type aliases, immutability patterns, error handling with unknown, input validation using Zod, and JSDoc usage with practical examples.

Changes

Cohort / File(s) Summary
TypeScript Coding Style Guide
rules/typescript/coding-style.md
Introduces comprehensive style guidance with examples for public API type annotations, interface-based patterns, immutability with Readonly<>, error handling with unknown type narrowing, Zod-based input validation, and JSDoc usage for type clarity. Updates console.log wording toward production focus.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop, hop, arrays of types so bright,
Interfaces dancing in TypeScript light,
Readonly whispers, no mutations today,
Zod validates errors in every way,
Clean code conventions, a style guide's delight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: enhancing TypeScript coding style guidelines with new sections on types, interfaces, error handling, and input validation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="rules/typescript/coding-style.md">

<violation number="1" location="rules/typescript/coding-style.md:158">
P2: The `getErrorMessage` helper appears in both the "Avoid `any`" section and the "Error Handling" section with different fallback strings (`'Unknown error'` vs `'Unexpected error'`). In a style guide, readers are likely to copy one of these as a reference — having two slightly different versions of the same function creates unnecessary ambiguity. Align the fallback message so both examples are consistent.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

return error.message
}

return 'Unexpected error'
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The getErrorMessage helper appears in both the "Avoid any" section and the "Error Handling" section with different fallback strings ('Unknown error' vs 'Unexpected error'). In a style guide, readers are likely to copy one of these as a reference — having two slightly different versions of the same function creates unnecessary ambiguity. Align the fallback message so both examples are consistent.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At rules/typescript/coding-style.md, line 158:

<comment>The `getErrorMessage` helper appears in both the "Avoid `any`" section and the "Error Handling" section with different fallback strings (`'Unknown error'` vs `'Unexpected error'`). In a style guide, readers are likely to copy one of these as a reference — having two slightly different versions of the same function creates unnecessary ambiguity. Align the fallback message so both examples are consistent.</comment>

<file context>
@@ -31,31 +140,50 @@ function updateUser(user, name) {
+    return error.message
+  }
+
+  return 'Unexpected error'
+}
+
</file context>
Suggested change
return 'Unexpected error'
return 'Unknown error'
Fix with Cubic

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
rules/typescript/coding-style.md (1)

141-170: Solid error handling pattern, but note console.error usage.

The async/await with try-catch pattern and unknown error narrowing are correct and align with best practices. However, line 166 uses console.error while lines 191-192 recommend using proper logging libraries instead of console methods.

Consider clarifying the logging approach

You might want to either:

  1. Add a comment in the example noting that console.error is used for simplicity but a logging library should be used in production, or
  2. Update the example to reference a logging library (even if pseudo-code), or
  3. Clarify in the Console.log section that console.error may be acceptable for server-side error logging

Example clarification:

async function loadUser(userId: string): Promise<User> {
  try {
    const result = await riskyOperation(userId)
    return result
  } catch (error: unknown) {
    // In production, use a proper logging library (e.g., winston, pino)
    logger.error('Operation failed:', error)
    throw new Error(getErrorMessage(error))
  }
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rules/typescript/coding-style.md` around lines 141 - 170, The example's error
logging in loadUser uses console.error; update it to demonstrate the recommended
approach by replacing console.error with a call to a logging abstraction (e.g.,
logger.error) or add an inline comment clarifying console.error is only for
simplicity and that a production logger (winston/pino) should be used; ensure
the catch still narrows unknown via getErrorMessage and rethrows the Error, and
reference loadUser, riskyOperation, and getErrorMessage so reviewers can find
and update the example.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@rules/typescript/coding-style.md`:
- Around line 141-170: The example's error logging in loadUser uses
console.error; update it to demonstrate the recommended approach by replacing
console.error with a call to a logging abstraction (e.g., logger.error) or add
an inline comment clarifying console.error is only for simplicity and that a
production logger (winston/pino) should be used; ensure the catch still narrows
unknown via getErrorMessage and rethrows the Error, and reference loadUser,
riskyOperation, and getErrorMessage so reviewers can find and update the
example.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aa8c6b19-150a-4821-ac64-8844fa568550

📥 Commits

Reviewing files that changed from the base of the PR and between 0f416b0 and d4c6449.

📒 Files selected for processing (1)
  • rules/typescript/coding-style.md

Copy link
Owner

@affaan-m affaan-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: doc-only changes look good. Approving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants