Skip to content

Typescript generated client type error with slice optional query parameters #924

@PhakornKiong

Description

@PhakornKiong

Generated a typescript client that have optional query parameters that is slice of string.

encore gen client -e local -l typescript > ./client.ts

type queryParameters struct {
	Name []string `query:"id" encore:"optional"`
}

func World(ctx context.Context, query queryParameters) (*Response, error) {
	rlog.Debug("hello world", "query", query)
	msg := "Hello, " + "!"
	return &Response{Message: msg}, nil
}

result in

export interface queryParameters {
        Name?: string[]
    }

const query = makeRecord<string, string | string[]>({
      id: params.Name.map((v) => v),
  })

and IDE is complaining that params.Name might be undefined.

Reproducible repo
https://github.com/PhakornKiong/encore-ts-codegen/blob/master/client.ts

Probably can be fixed by optional chaining?
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions