Skip to content

Refactor codebase for improved type safety and maintainability - #154

Merged
Atis9 merged 3 commits into
mainfrom
feature/claude/refactor-codebase
Feb 10, 2026
Merged

Refactor codebase for improved type safety and maintainability#154
Atis9 merged 3 commits into
mainfrom
feature/claude/refactor-codebase

Conversation

@Atis9

@Atis9 Atis9 commented Feb 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extract ProfileCard component from Layout for better separation of concerns
  • Simplify lib/posts.ts with helper functions (extractMetadata) and leverage TypeScript inference
  • Fix primitive type usage (Booleanboolean)
  • Add stricter TypeScript compiler options
  • Remove redundant code (type annotations, deprecated props, duplicate CSS)

Changes

File Change
components/profile.tsx New component with profile data and ProfileCard
components/layout.tsx Simplified using ProfileCard, added LayoutProps interface
lib/posts.ts Refactored with helper functions, Post extends PostSummary
app/page.tsx Removed passHref and unused import
app/posts/[id]/page.tsx Added PageProps interface, simplified param handling
tsconfig.json Added noUnusedLocals, noUnusedParameters, noFallthroughCasesInSwitch
styles/globals.scss Removed duplicate font-family declaration

Test plan

  • All tests pass (npm test)
  • Build succeeds (npm run build)
  • Lint passes (npm run lint)

🤖 Generated with Claude Code

- Extract ProfileCard component from Layout
- Simplify lib/posts.ts with helper functions and type inference
- Fix Boolean -> boolean return type
- Add stricter TypeScript options (noUnusedLocals, noUnusedParameters)
- Remove redundant type annotations and unused imports
- Remove deprecated passHref prop from Link
- Remove duplicate font-family declaration in SCSS

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 10, 2026 05:05
@vercel

vercel Bot commented Feb 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nyantech-com Ready Ready Preview, Comment Feb 10, 2026 5:22am

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Next.js/TypeScript codebase to improve maintainability and type-safety by extracting the profile UI into a dedicated component, simplifying post-loading utilities, tightening TypeScript compiler checks, and removing redundant code/styles.

Changes:

  • Extracted a new ProfileCard component (and shared profile data) and updated Layout + layout tests accordingly.
  • Refactored lib/posts.ts to reduce duplication (metadata extraction, sorting, ID validation) and improve typing.
  • Tightened TS compiler options and removed minor redundancies (e.g., passHref, duplicate CSS, unused params).

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
components/profile.tsx New profile component + profile metadata export.
components/layout.tsx Uses ProfileCard and derives exported name from shared profile data.
components/layout.test.tsx Updates assertions to use shared profile metadata.
lib/posts.ts Refactors post metadata extraction, sorting, ID validation, and error type.
app/page.tsx Removes redundant type annotation/import and removes passHref.
app/posts/[id]/page.tsx Simplifies static params generation and adds props interface + sanitization comment.
app/api/hello/route.ts Removes unused request parameter (aligns with stricter TS flags).
__tests__/posts-page.test.tsx Updates tests for the posts page exports.
__tests__/api-hello.test.ts Updates tests to call GET() without a dummy request.
tsconfig.json Enables noUnusedLocals, noUnusedParameters, noFallthroughCasesInSwitch.
styles/globals.scss Removes duplicate font-family override for .markdown-body.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/posts/[id]/page.tsx
Comment thread __tests__/posts-page.test.tsx
Comment thread components/profile.tsx Outdated
Move Profile/ProfileLink types and profile constant to profile-data.ts
to decouple data from React/Next.js dependencies.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 10, 2026 05:21
@Atis9
Atis9 merged commit cdd13d9 into main Feb 10, 2026
9 checks passed
@Atis9
Atis9 deleted the feature/claude/refactor-codebase branch February 10, 2026 05:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 13 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/posts/[id]/page.tsx
Comment on lines +8 to 10
interface PageProps {
params: Promise<{ id: string }>;
}

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

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

params is typed as Promise<{ id: string }> and then awaited, but in Next.js App Router params is passed as a plain object. Keeping it as a Promise can cause type-checking mismatches with Next’s generated PageProps types and forces callers/tests to wrap params in Promise.resolve. Recommend changing PageProps.params back to { id: string } and removing the unnecessary await usage in generateMetadata and PostPage.

Copilot uses AI. Check for mistakes.
Comment on lines 24 to 32
it('generateMetadataが正しいメタデータを返す', async () => {
const metadata = await generateMetadata({ params: { id: 'test-post' } });
const metadata = await generateMetadata({ params: Promise.resolve({ id: 'test-post' }) });
expect(metadata.title).toBe('テスト投稿タイトル - Nyantech');
expect(metadata.description).toBe('テスト投稿タイトル');
});

it('投稿タイトルが表示される', async () => {
const params = { id: 'test-post' };
const PostComponent = await PostPage({ params });
const PostComponent = await PostPage({ params: Promise.resolve({ id: 'test-post' }) });
render(PostComponent);

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

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

The tests now pass params: Promise.resolve(...) to match the page’s params: Promise<{id: string}> typing. If params is corrected to the standard { id: string } object (as Next.js provides at runtime), these tests should be updated back to pass a plain object to better reflect real usage and avoid unnecessary async wrappers.

Copilot uses AI. Check for mistakes.
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