-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Maintenance] Migrating util.js and chartTheme.js to typescript #2009
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Bundle Stats — desktop-clientHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset No files were changed View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
Bundle Stats — loot-coreHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset No files were changed View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hi @ghosetuhin ! Thanks for your first contribution! I left a couple of comments that I hope won't be too tricky for you to solve. And once they are solved I'll be happy to merge this PR :)
redFadeEnd: string; | ||
}; | ||
|
||
let colorFades: ColorFades = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: this type is automatically inferred. There's no point in manually recreating it if we're not re-using it in multiple places.
let colorFades: ColorFades = { | |
let colorFades = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! Made the changes!
stroke: string; | ||
}; | ||
|
||
const baseLabelStyles: LabelStyles = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: same issue here
const baseLabelStyles: LabelStyles = { | |
const baseLabelStyles = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it
tickLabels: LabelStyles; | ||
}; | ||
|
||
const axisBaseStyles: AxisBaseStyles = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: and here
const axisBaseStyles: AxisBaseStyles = { | |
const axisBaseStyles = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it
}; | ||
}; | ||
|
||
export const chartTheme: ChartTheme = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: and here
export const chartTheme: ChartTheme = { | |
export const chartTheme = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it
}; | ||
|
||
export function getColorScale(name: string): string[] { | ||
const scales: ColorScales = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: would be better to use an inline style here if we want to be super-strict. Although personally I wouldn't add a manual type to it. Up to you.
const scales: ColorScales = { | |
const scales: Record<string, string[]> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented it inline. Thanks for the suggestion!
@@ -13,23 +17,23 @@ export async function runAll(queries, cb) { | |||
cb(data); | |||
} | |||
|
|||
export function index(data, field, mapper) { | |||
export function index(data, field: string, mapper?: (input) => unknown) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: could be improved with generics
export function index(data, field: string, mapper?: (input) => unknown) { | |
export function index<T, K extends keyof T>(data: T[], field: K, mapper?: (input: T[K]) => string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at this. I implemented it using generics this time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the generics I implemented using the way you suggested were failing the type checks for some reason with the error Argument of type 'string' is not assignable to parameter of type 'never'. I tried playing around with it but couldn't fix it. Had to finally resort to using string as the type for some fields
const result = {}; | ||
data.forEach(item => { | ||
result[mapper ? mapper(item[field]) : item[field]] = item; | ||
}); | ||
return result; | ||
} | ||
|
||
export function indexStack(data, fieldName, field) { | ||
export function indexStack(data, fieldName: string, field: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: this one and also indexCashFlow
(below) could be improved with generics too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried implementing it for indexCashFlow but it is not taking generic types quite well
@@ -13,23 +17,24 @@ export async function runAll(queries, cb) { | |||
cb(data); | |||
} | |||
|
|||
export function index(data, field, mapper) { | |||
const result = {}; | |||
export function index<T>(data: T[], field: string, mapper?: (input) => string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was a pretty fun problem to solve. Here you go: https://gist.github.com/MatissJanis/307e49bbeec34f2975709e0ec3bc3100 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Thanks for this! I implemented these changes!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Link to issue: #1483
Replaced util.js with util.ts
Replaced chart-theme.js with chart-theme.ts