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

chore: Typescript generator TODOs resolved, adding explainations#6633

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 4 commits intomainfromstevenmasley/typescript_gen_todo
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletionsscripts/apitypings/main.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -633,6 +633,8 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
}
case *types.Struct:
// This handles anonymous structs. This should never happen really.
// If you require this, either change your datastructures, or implement
// anonymous structs here.
// Such as:
// type Name struct {
// Embedded struct {
Expand All@@ -643,7 +645,8 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
ValueType: "any",
AboveTypeLine: fmt.Sprintf("%s\n%s",
indentedComment("Embedded anonymous struct, please fix by naming it"),
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed"),
// Linter needs to be disabled here, or else it will complain about the "any" type.
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Anonymously embedded struct"),
),
}, nil
case *types.Map:
Expand DownExpand Up@@ -766,9 +769,14 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {

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

Expand All@@ -789,14 +797,28 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
resp.Optional = true
return resp, nil
case *types.Interface:
// only handle the empty interface for now
// only handle the empty interface(interface{})for now
intf := ty
if intf.Empty() {
// This field is 'interface{}'. We can't infer any type from 'interface{}'
// so just use "any" as the type.
return TypescriptType{
ValueType: "any",
AboveTypeLine: indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed"),
ValueType: "any",
AboveTypeLine: fmt.Sprintf("%s\n%s",
indentedComment("Empty interface{} type, cannot resolve the type."),
// Linter needs to be disabled here, or else it will complain about the "any" type.
indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}"),
),
}, nil
}
// All complex interfaces should be named. So if we get here, that means
// we are using anonymous interfaces. Which is just weird and not supported.
// Example:
// type Foo struct {
// Bar interface {
// Baz() string
// }
// }
return TypescriptType{}, xerrors.New("only empty interface types are supported")
case *types.TypeParam:
_, ok := ty.Underlying().(*types.Interface)
Expand Down
26 changes: 15 additions & 11 deletionssite/src/api/typesGenerated.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,9 +53,11 @@ export type AuditDiff = Record<string, AuditDiffField>

// From codersdk/audit.go
export interface AuditDiffField {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed
// Empty interface{} type, cannot resolve the type.
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}
readonly old?: any
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed
// Empty interface{} type, cannot resolve the type.
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}
readonly new?: any
readonly secret: boolean
}
Expand All@@ -67,7 +69,7 @@ export interface AuditLog {
readonly time: string
readonly organization_id: string
// Named type "net/netip.Addr" unknown, using "any"
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
readonly ip: any
readonly user_agent: string
readonly resource_type: ResourceType
Expand DownExpand Up@@ -357,12 +359,12 @@ export interface DeploymentValues {
readonly disable_password_auth?: boolean
readonly support?: SupportConfig
// Named type "github.com/coder/coder/cli/clibase.Struct[[]github.com/coder/coder/codersdk.GitAuthConfig]" unknown, using "any"
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
readonly git_auth?: any
readonly config?: string
readonly write_config?: boolean
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
readonly address?: any
}

Expand DownExpand Up@@ -441,7 +443,8 @@ export interface License {
readonly id: number
readonly uuid: string
readonly uploaded_at: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed
// Empty interface{} type, cannot resolve the type.
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}
readonly claims: Record<string, any>
}

Expand DownExpand Up@@ -577,15 +580,15 @@ export interface PatchGroupRequest {
export interface PprofConfig {
readonly enable: boolean
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
readonly address: any
}

// From codersdk/deployment.go
export interface PrometheusConfig {
readonly enable: boolean
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
readonly address: any
}

Expand DownExpand Up@@ -670,7 +673,8 @@ export interface Role {
// From codersdk/serversentevents.go
export interface ServerSentEvent {
readonly type: ServerSentEventType
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO explain why this is needed
// Empty interface{} type, cannot resolve the type.
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}
readonly data: any
}

Expand All@@ -692,7 +696,7 @@ export interface SessionCountDeploymentStats {
// From codersdk/deployment.go
export interface SupportConfig {
// Named type "github.com/coder/coder/cli/clibase.Struct[[]github.com/coder/coder/codersdk.LinkConfig]" unknown, using "any"
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
readonly links: any
}

Expand All@@ -705,7 +709,7 @@ export interface SwaggerConfig {
export interface TLSConfig {
readonly enable: boolean
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
// eslint-disable-next-line @typescript-eslint/no-explicit-any --TODO explain why this is needed
// eslint-disable-next-line @typescript-eslint/no-explicit-any --External type
readonly address: any
readonly redirect_http: boolean
readonly cert_file: string[]
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp