-
Notifications
You must be signed in to change notification settings - Fork 16
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
Use Typescript #71
Use Typescript #71
Conversation
The only anoyance is the fact that transform = new ZoomTransform(p.k, p.x, p.y);
draw.setTransform(transform);
redraw(); Maybe @weeman1337 has an idea here? |
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 migrating the project to TypeScript. Left some notes.
Also ESLint explodes, because it cannot parse TypeScript:
npm i --save-dev @typescript-eslint/parser
- Add
"parser": "@typescript-eslint/parser"
to.eslintrc.json
lib/container.ts
Outdated
tag = "div"; | ||
} | ||
|
||
let self = { |
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.
If a variable is not reassigned, it should be declared as const
(counts for other places as well)
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 wanted to change as little as needed here to not make the changes more confusing than they already are but can change it at least for the self's
lib/forcegraph.ts
Outdated
@@ -42,64 +54,69 @@ export const ForceGraph = function (linkScale, sidebar) { | |||
draw.setMaxArea(canvas.width, canvas.height); | |||
} | |||
|
|||
function transformPosition(p) { | |||
function transformPosition(p: { k: number; x: number; y: number }) { | |||
// @ts-ignore |
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.
To solve this ignore transform should be replaced with a new instance
transform = new d3Zoom.ZoomTransform(p.k, p.x, p.y);
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 would love doing that but that breaks it even more, see the comments above.
Can you eventually show me exactly how you mean that at some point?
|
||
if (node !== undefined) { | ||
// @ts-ignore |
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.
Is node
actually something different here?
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.
Is should be some kind of MapNode
that has an o
attribute with the actual node
@@ -26,9 +36,12 @@ export const Main = function (sidebar, linkScale) { | |||
|
|||
el.scrollIntoView(false); | |||
el.classList.add("infobox"); | |||
// @ts-ignore |
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.
If destroy()
should be kept with the element, you could use an extended element with the destroy()
function defined.
h2.classList.add("proportion-header"); | ||
h2.textContent = _.t(heading); | ||
h2.onclick = function onclick() { | ||
// @ts-ignore |
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.
renderSingle()
should return an extended table with the elm
prop.
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.
Tested, looks good and works!
Description
This replaces most .js files with their typescript equivalent.
Motivation and Context
Having no clue what something does is bad, this fixes it b having types and thus at least some clues 🎉
How Has This Been Tested?
On my laptop, technically should produce the same JS as before
Screenshots/links:
n/a
Checklist: