Skip to content

Conversation

@imkesin
Copy link
Contributor

@imkesin imkesin commented May 20, 2025

Description

I've wanted to improve this for a long time. One of the main motivations is to turn on noUncheckedIndexedAccess (and this is responsible for almost all of the changes).

@imkesin imkesin requested review from doneel and sarahraines May 20, 2025 21:46
@imkesin imkesin self-assigned this May 20, 2025
@promptless
Copy link

promptless bot commented May 20, 2025

✅ No documentation updates required.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR enables noUncheckedIndexedAccess in tsconfig.json to improve type safety across the codebase, requiring explicit null checks for array and object access.

  • Added @ts-expect-error comments in PeriodPicker.tsx for date string splitting, consider using a more type-safe date parsing approach
  • Changed module resolution to bundler and module to preserve in tsconfig.json, which needs careful testing for build compatibility
  • Marked isolatedModules and verbatimModuleSyntax as "resolve ASAP" but left disabled, should be addressed soon
  • Added ReadonlyArrayWithAtLeastOne type in Reports.tsx to ensure at least one report type is available
  • Improved color mapping safety in DetailedTable.tsx and ProfitAndLossSummariesMiniChart.tsx with nullish coalescing

31 file(s) reviewed, 7 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +142 to +148
if (rowState.splits[rowNumber]) {
rowState.splits[rowNumber].amount = newAmount
rowState.splits[rowNumber].inputValue = newDisplaying
}
if (rowState.splits[0]) {
rowState.splits[0].amount = remaining
rowState.splits[0].inputValue = formatMoney(remaining)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: State mutations should be avoided. Consider creating a new state object instead of directly modifying rowState.splits

Suggested change
if (rowState.splits[rowNumber]) {
rowState.splits[rowNumber].amount = newAmount
rowState.splits[rowNumber].inputValue = newDisplaying
}
if (rowState.splits[0]) {
rowState.splits[0].amount = remaining
rowState.splits[0].inputValue = formatMoney(remaining)
}
const newSplits = [...rowState.splits]
if (newSplits[rowNumber]) {
newSplits[rowNumber] = {
...newSplits[rowNumber],
amount: newAmount,
inputValue: newDisplaying
}
}
if (newSplits[0]) {
newSplits[0] = {
...newSplits[0],
amount: remaining,
inputValue: formatMoney(remaining)
}
}

accountId: data[i].accountId,
accountId: data?.[i]?.accountId ?? '',
}))
return onSuccess?.(resultsWithIds)
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: onSuccess callback is called with optional chaining but its type doesn't indicate it's optional

Suggested change
return onSuccess?.(resultsWithIds)
return onSuccess(resultsWithIds)

Comment on lines +216 to 220
// @ts-expect-error Guaranteed to produce `YYYY-MM-DD`
start_date: startDate.toISOString().split('T')[0],

// @ts-expect-error Guaranteed to produce `YYYY-MM-DD`
end_date: endDate.toISOString().split('T')[0],
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Using @ts-expect-error to bypass type checking is not ideal. Consider using a more type-safe approach like format(startDate, 'yyyy-MM-dd') from date-fns library which already exists in the project dependencies.

>
{chartData.map((entry, index) => {
let fill: string | undefined = typeColorMapping[index].color
let fill: string | undefined = typeColorMapping[index]?.color
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding a default color value if typeColorMapping[index] is undefined to maintain consistent visualization

Comment on lines +127 to +128
background: typeColorMapping[idx] ? typeColorMapping[idx].color : '#e6e6e6',
opacity: typeColorMapping[idx] ? typeColorMapping[idx].opacity : 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The fallback color '#e6e6e6' should use DEFAULT_COLOR_MAPPING.color for consistency

Suggested change
background: typeColorMapping[idx] ? typeColorMapping[idx].color : '#e6e6e6',
opacity: typeColorMapping[idx] ? typeColorMapping[idx].opacity : 1,
background: typeColorMapping[idx] ? typeColorMapping[idx].color : DEFAULT_COLOR_MAPPING.color,
opacity: typeColorMapping[idx] ? typeColorMapping[idx].opacity : DEFAULT_COLOR_MAPPING.opacity,

Comment on lines 198 to 202
return {
r: values[0],
g: values[1],
b: values[2],
r: values[0] ?? 0,
g: values[1] ?? 0,
b: values[2] ?? 0,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Using nullish coalescing with 0 as fallback could mask invalid hex values. Consider throwing an error if values[0-2] are undefined since this would indicate an invalid hex color.

@imkesin imkesin changed the base branch from main to release/next May 21, 2025 20:45
}

const DEFAULT_COLOR_MAPPING = {
color: '#EEEEF0',
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: I think this one should work too:

color: 'var(--color-base-200)

@imkesin imkesin force-pushed the imkesin/clean-tsconfig branch from bcec4a1 to 5a4f693 Compare June 25, 2025 18:58
@imkesin imkesin changed the base branch from release/next to main June 25, 2025 18:59
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.

3 participants