Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite55d921

Browse files
authored
chore: Typescript generator TODOs resolved, adding explainations (#6633)
* chore: Explain usage of eslint comments* Conform comment* Fix wording* Linting
1 parentb1c1e1a commite55d921

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

‎scripts/apitypings/main.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
633633
}
634634
case*types.Struct:
635635
// This handles anonymous structs. This should never happen really.
636+
// If you require this, either change your datastructures, or implement
637+
// anonymous structs here.
636638
// Such as:
637639
// type Name struct {
638640
// Embedded struct {
@@ -643,7 +645,8 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
643645
ValueType:"any",
644646
AboveTypeLine:fmt.Sprintf("%s\n%s",
645647
indentedComment("Embedded anonymous struct, please fix by naming it"),
646-
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed"),
648+
// Linter needs to be disabled here, or else it will complain about the "any" type.
649+
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Anonymously embedded struct"),
647650
),
648651
},nil
649652
case*types.Map:
@@ -766,9 +769,14 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
766769

767770
// If it's a struct, just use the name of the struct type
768771
if_,ok:=n.Underlying().(*types.Struct);ok {
772+
// External structs cannot be introspected, as we only parse the codersdk package.
773+
// You can handle your type manually in the switch list above, otherwise "any" will be used.
774+
// An easy way to fix this is to pull your external type into `codersdk` package, then it will
775+
// be known by the generator.
769776
returnTypescriptType{ValueType:"any",AboveTypeLine:fmt.Sprintf("%s\n%s",
770777
indentedComment(fmt.Sprintf("Named type %q unknown, using\"any\"",n.String())),
771-
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed"),
778+
// Linter needs to be disabled here, or else it will complain about the "any" type.
779+
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- External type"),
772780
)},nil
773781
}
774782

@@ -789,14 +797,28 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
789797
resp.Optional=true
790798
returnresp,nil
791799
case*types.Interface:
792-
// only handle the empty interface for now
800+
// only handle the empty interface(interface{})for now
793801
intf:=ty
794802
ifintf.Empty() {
803+
// This field is 'interface{}'. We can't infer any type from 'interface{}'
804+
// so just use "any" as the type.
795805
returnTypescriptType{
796-
ValueType:"any",
797-
AboveTypeLine:indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed"),
806+
ValueType:"any",
807+
AboveTypeLine:fmt.Sprintf("%s\n%s",
808+
indentedComment("Empty interface{} type, cannot resolve the type."),
809+
// Linter needs to be disabled here, or else it will complain about the "any" type.
810+
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}"),
811+
),
798812
},nil
799813
}
814+
// All complex interfaces should be named. So if we get here, that means
815+
// we are using anonymous interfaces. Which is just weird and not supported.
816+
// Example:
817+
// type Foo struct {
818+
// Bar interface {
819+
// Baz() string
820+
// }
821+
// }
800822
returnTypescriptType{},xerrors.New("only empty interface types are supported")
801823
case*types.TypeParam:
802824
_,ok:=ty.Underlying().(*types.Interface)

‎site/src/api/typesGenerated.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ export type AuditDiff = Record<string, AuditDiffField>
5353

5454
// From codersdk/audit.go
5555
exportinterfaceAuditDiffField{
56-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed
56+
// Empty interface{} type, cannot resolve the type.
57+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}
5758
readonlyold?:any
58-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed
59+
// Empty interface{} type, cannot resolve the type.
60+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}
5961
readonlynew?:any
6062
readonlysecret:boolean
6163
}
@@ -67,7 +69,7 @@ export interface AuditLog {
6769
readonlytime:string
6870
readonlyorganization_id:string
6971
// Named type "net/netip.Addr" unknown, using "any"
70-
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
72+
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
7173
readonlyip:any
7274
readonlyuser_agent:string
7375
readonlyresource_type:ResourceType
@@ -357,13 +359,13 @@ export interface DeploymentValues {
357359
readonlydisable_password_auth?:boolean
358360
readonlysupport?:SupportConfig
359361
// Named type "github.com/coder/coder/cli/clibase.Struct[[]github.com/coder/coder/codersdk.GitAuthConfig]" unknown, using "any"
360-
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
362+
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
361363
readonlygit_auth?:any
362364
readonlyconfig_ssh?:SSHConfig
363365
readonlyconfig?:string
364366
readonlywrite_config?:boolean
365367
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
366-
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
368+
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
367369
readonlyaddress?:any
368370
}
369371

@@ -442,7 +444,8 @@ export interface License {
442444
readonlyid:number
443445
readonlyuuid:string
444446
readonlyuploaded_at:string
445-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed
447+
// Empty interface{} type, cannot resolve the type.
448+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}
446449
readonlyclaims:Record<string,any>
447450
}
448451

@@ -578,15 +581,15 @@ export interface PatchGroupRequest {
578581
exportinterfacePprofConfig{
579582
readonlyenable:boolean
580583
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
581-
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
584+
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
582585
readonlyaddress:any
583586
}
584587

585588
// From codersdk/deployment.go
586589
exportinterfacePrometheusConfig{
587590
readonlyenable:boolean
588591
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
589-
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
592+
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
590593
readonlyaddress:any
591594
}
592595

@@ -683,7 +686,8 @@ export interface SSHConfigResponse {
683686
// From codersdk/serversentevents.go
684687
exportinterfaceServerSentEvent{
685688
readonlytype:ServerSentEventType
686-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed
689+
// Empty interface{} type, cannot resolve the type.
690+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}
687691
readonlydata:any
688692
}
689693

@@ -705,7 +709,7 @@ export interface SessionCountDeploymentStats {
705709
// From codersdk/deployment.go
706710
exportinterfaceSupportConfig{
707711
// Named type "github.com/coder/coder/cli/clibase.Struct[[]github.com/coder/coder/codersdk.LinkConfig]" unknown, using "any"
708-
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
712+
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
709713
readonlylinks:any
710714
}
711715

@@ -718,7 +722,7 @@ export interface SwaggerConfig {
718722
exportinterfaceTLSConfig{
719723
readonlyenable:boolean
720724
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
721-
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
725+
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
722726
readonlyaddress:any
723727
readonlyredirect_http:boolean
724728
readonlycert_file:string[]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp