-
Notifications
You must be signed in to change notification settings - Fork 881
feat: generate typescript types from codersdk structs #1047
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1047 +/- ##
==========================================
- Coverage 67.42% 66.66% -0.76%
==========================================
Files 260 261 +1
Lines 15374 15502 +128
Branches 152 152
==========================================
- Hits 10366 10335 -31
- Misses 3966 4118 +152
- Partials 1042 1049 +7
Continue to review full report at Codecov.
|
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 love this concept, I was just talking to @code-asher about a really sneaky bug we ran into from having a hand-written type mismatch. There were no compiler warnings or runtime errors or logs, just a field wasn't there, and none of the calling code caused an exception because it handled undefined
gracefully.
The one thing (which I don't think blocks anything, more of a FYI type of comment), is that we want to also add mocks for all types we add. It's OK if we still need to do that by hand, just means that you can't auto-generate and fire/forget, you'll have some manual work to do after generating.
Love this ❤️
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.
Very exciting!
coderts/generate.go
Outdated
@@ -0,0 +1,111 @@ | |||
package main |
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.
Should we just put this in cmd/typings
or something?
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 thought about that but think this fits much more as a "generate.sh" type of script. I connected it to our make gen command, which I think fits nicer than making it a top level command.
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.
It breaks the idiom of all commands being inside the cmd
folder. We have the DataDog CI report helper in scripts/datadog-cireport
, so it could be there 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.
Yeah it's not a command it's just a script that happens to be go. I'll move to scripts if we want. Is this really any different than the scripts in the coderd/database
package? Or should those move into scripts
as well ideally?
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 think dump
should totally move into scripts too. It's just nice to know whether a package should be imported or not based on folder structure.
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.
cool I moved it
coderts/types.ts
Outdated
@@ -0,0 +1,172 @@ | |||
export interface BuildInfoResponse { |
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.
We could make these link directly to the Go files too... could be neat for documentation.
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.
Working on generating docs, may happen in this PR or a follow up.
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.
added the doc codelines
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.
That is cool af
This feels mergeable at this point for me, I'm going to continue down this path to generate docs as well but don't want that blocking this. |
coderts/types.ts
Outdated
@@ -0,0 +1,260 @@ | |||
// From codersdk/buildinfo.go:10:6. |
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.
Could we move this into site/src/api/types.ts
instead? Otherwise, the site has to import outside of itself, which has caused issues in the past.
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.
totally
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.
Awesome awesome. Approvin'
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.
We might want to rename coderts
to apitypings
or something more specified. Right now it's kinda unclear what it's doing. apitypings
isn't great either though so 🤷
Let's remove experiment
from the title too, since this has really been upgraded to a full-on feature 🦘🦘🦘
Since I'm moving it under the api directory it doesn't really matter the name anymore outside the command name. I'll make the change. |
Ahh my bad I should have been specific. I just mean for the |
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.
type WorkspaceAgentStatus = "connected" | "connecting" | "disconnected"
If it's easier for formatting, you can write it like this:
type Thing =
| "a"
| "b"
| "c"
and just let prettier take care of the formatting (the above is valid TS)
748365d
to
a1f5044
Compare
@kylecarbs @vapurrmaid any idea why the CI is failing? I'm not sure why it's not seeing prettier in one of them, and the other I can't figure out why it fails |
Ok I had broken my prettier command when I renamed the files |
Ok @kylecarbs I can't figure out why the make gen is different on my machine than CI. :/ |
My machine still has the following: (unsure if related)
This is in my dogfood workspace so I'm not sure why I'm always out of sync. |
My workspace still is making incorrect output from make/gen, but I just changed it to what CI wanted to unblock myself. |
This isn't quite there yet, but I wanted to see how close I could get if I timeboxed to 30 minutes. I couldn't find any decent looking libraries in go to do this that didn't complicate things, so I reached for the go AST.
If we like this idea we could see how much work it would take to make this usable.
Update:
I've worked on making this production ready for us to use on the frontend. This generates a new types-generated.ts file that the frontend team can migrate to.