-
-
Notifications
You must be signed in to change notification settings - Fork 622
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
feat(context): ResponseInit
accepts generics StatusCode
for status
#3770
Conversation
Bundle size check
Compiler Diagnostics
Reported by octocov |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3770 +/- ##
========================================
Coverage 91.72% 91.72%
========================================
Files 159 159
Lines 10175 10175
Branches 2991 2847 -144
========================================
Hits 9333 9333
Misses 841 841
Partials 1 1 ☔ View full report in Codecov by Sentry. |
statusText?: string | ||
} | ||
|
||
type ResponseOrInit<T extends StatusCode = StatusCode> = ResponseInit<T> | Response |
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.
What do you think of this PR? |
@yusukebe i like this PR & the code looks good to me. Is there any way to measure the TS performance degradation this can cause? |
I think it is a good feature. |
Thanks for the comments! You can refer to the |
Hey, @m-shaka. What do you think of the change in TypeScript performance due to this PR? |
@yusukebe @EdamAme-x I think the subject of types is a part of a much greater discussion, but to put it simply I think less inference overall = better. I think the Hono Context as a concept makes it hard to make Hono scalable enough for the Typescript compiler. In this particular case, if each context method, such as .text() or .json() were to return a set of properties such as |
That being said, I think this particular PR will not change things much in terms of TS performance, but we have to be careful overall about populating Hono's context with more TS. As for the performance metrics I will need to run some more benchmarks to get more sample data |
Speaking of this change, I think it is necessary to make As for the performance of TypeScript, it is ideal to optimize it as a separate issue. |
@yusukebe makes sense. From what I can say from the performance metrics above, the numbers we have to pay attention to most is |
Our test case doesn't use the second argument of hono/perf-measures/type-check/scripts/generate-app.ts Lines 8 to 18 in b1335f9
|
I added
|
@askorupskyy @EdamAme-x @m-shaka Thank you! Let's go with this. Merging now. |
From merging #3763,
c.json()
orc.text()
can no longer have a contentless status code as the second argument.In this PR, if a method such as
c.json()
hasResponseInit
as its second argument, specifying contentless code for the status property will cause a type error.This is the correct behavior, and I think this PR should be accepted. However, it causes minor performance degradation in TypeScript, so we need to be careful about it.
The author should do the following, if applicable
bun run format:fix && bun run lint:fix
to format the code