-
Notifications
You must be signed in to change notification settings - Fork 80
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
Convert some code to TypeScript #655
Conversation
Hey there @unional ! I'm converting everything to Typescript on the newFocusArch and newPreferences branches that contain the 2.0 version of Bazecor, which entails:
so if you want to help out with this tell me and I will incorporate the changes with development to atomize the migration in different PRs so you and others can contribute! |
Sounds good. I'm also thinking about virtual keyboard. For that, the way the code is written needs to change. e.g. define a proper interface of the keyboards and the business logic (high-level policies) only consume interfaces. Another approach is to use inheritance, with abstract class etc (similar to just interface, but more liberate and more OO-like) |
That's a very good approach to further leverage the virtual keyboard's concept! in fact, one of the reasons to develop that feature was to test out the interface without requiring access to a physical version of the keyboard. it would be very nice to be able to write tests against the same endpoints that are used for regular functionality. I will explore this concept and probably will create a discussion around it, so we can polish the concept 💎 |
@alexpargon how would you like to organize the tests? I typically does not do
There are other kind of tests, e.g. Also, I can introduce storybook, visual snapshot testing, interactive tests, etc. |
@@ -166,7 +141,7 @@ export var arduino = { | |||
let { address } = dataObjects[0]; | |||
|
|||
if (address < 2000) { | |||
finished(true, `You're attempting to overwrite the bootloader... (0x${padToN(num2hexstr(dataObjects[0].address), 8)})`); |
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.
this is simplified as num2hexstr
calls padToN
already.
The simple functions are extracted. The We can do that in another PR. |
I have also updated the Also added a stricter tsconfig for testing newer code. We can gradually improve the code quality and switch over in the future. |
@@ -26,7 +26,7 @@ export function decodeHexLine(line: string) { | |||
const bytes = new ArrayBuffer(byteData.length); | |||
const bytesView = new Uint8Array(bytes, 0, byteData.length); | |||
|
|||
for (let i = 0; i < byteData.length; i++) bytesView[i] = byteData[i]; |
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.
This is updated to better infer types.
Test has this covered.
vite.config.mts
Outdated
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 file extension is changed to .mts
as the CJS build for vitest
is deprecated.
ESM code needs either type: module
or .mts
.
} | ||
}, | ||
"include": ["src/**/*"], | ||
"files": ["src/renderer/theme/styled.d.ts"] |
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.
This line is removed because include
includes it.
This is likely introduced when the file is drag or renamed on vscode.
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"strict": true, | ||
// "verbatimModuleSyntax": true // requires TypeScript 5 |
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.
Currently this cannot be enabled because the project is using TypeScript 4.5.
Maybe we can upgrade it in another PR?
Note that I have converted |
This allows quick check of typescript error without running `yarn make-dev` which is much slower
The conversion will be done in many small PRs, so that the changes can be merged quickly, minimizing merge conflicts for the team.
The name does not accurately match behavior. Suggest fixing it in the future
`w` is the convention I use as I'm lazy. Feel free to suggest otherwise
the `num2hexstr` usage actually shows that the first param is a string, and the second param is opional based on the commented console log. the value is defaults to 0 to better match its intent and passes type check.
Great Job @unional ! 😄 really appreciate your help with this 👍🏻 |
The conversion will be done in many small PRs,
so that the changes can be merged quickly,
minimizing merge conflicts for the team.
The
Error
component is converted to a functional component, and show that the error prop is not being used.