Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/lib/cardOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const VALID_BLOCKS: CardBlockType[] = [
];
export const VALID_LAYOUT_SLOTS: CardLayoutSlot[] = ["left", "right", "full"];

export const DEFAULT_WIDTH = 600;
export const MIN_WIDTH = 320;
export const MAX_WIDTH = 1400;
Comment on lines +33 to +35

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.

P2 as const アサーションを付けると、TypeScript がこれらの定数をリテラル型 (600, 320, 1400) として扱うため、意図せず別の number 値が代入されることをコンパイル時に防げます。PR 説明で「explicitly typed as constants」と述べている趣旨とも一致します。

Suggested change
export const DEFAULT_WIDTH = 600;
export const MIN_WIDTH = 320;
export const MAX_WIDTH = 1400;
export const DEFAULT_WIDTH = 600 as const;
export const MIN_WIDTH = 320 as const;
export const MAX_WIDTH = 1400 as const;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/cardOptions.ts
Line: 33-35

Comment:
`as const` アサーションを付けると、TypeScript がこれらの定数をリテラル型 (`600`, `320`, `1400`) として扱うため、意図せず別の `number` 値が代入されることをコンパイル時に防げます。PR 説明で「explicitly typed as constants」と述べている趣旨とも一致します。

```suggestion
export const DEFAULT_WIDTH = 600 as const;
export const MIN_WIDTH = 320 as const;
export const MAX_WIDTH = 1400 as const;
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


function toList(csv: string | null): string[] {
if (!csv) {
return [];
Expand All @@ -42,11 +46,11 @@ function toList(csv: string | null): string[] {

function parseWidth(raw: string | null): number {
if (!raw) {
return 600;
return DEFAULT_WIDTH;
}
const value = Number.parseInt(raw, 10);
if (!Number.isFinite(value) || value < 320 || value > 1400) {
return 600;
if (!Number.isFinite(value) || value < MIN_WIDTH || value > MAX_WIDTH) {
return DEFAULT_WIDTH;
}
return value;
}
Expand Down
Loading