Skip to content
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(goctl): better generate the api code of typescript #2483

Merged
merged 1 commit into from Oct 11, 2022
Merged

feat(goctl): better generate the api code of typescript #2483

merged 1 commit into from Oct 11, 2022

Conversation

foliet
Copy link
Contributor

@foliet foliet commented Oct 5, 2022

When generating the api code of typescript, if the tag contains the options modifier, the union type is generated instead of the declared type. Here is an example.

Api:

type SomeType {
	Foo string `json:"foo,options=foo,bar,options,123"`
	Bar int `json:"bar,options=1,3,4,123"`
}

Typescript:

export interface SomeType {
    foo: 'foo' | 'bar' | 'options' | '123'
    bar: 1 | 3 | 4 | 123
}

This can provide a good intelligent complement for the front-end IDE.

I have completed the test file.

@foliet
Copy link
Contributor Author

foliet commented Oct 6, 2022

As a comparison, the past output is:

export interface SomeType {
    foo: string
    bar: number
}

@kevwan
Copy link
Contributor

kevwan commented Oct 11, 2022

No need to define type in ts?

As a comparison, the past output is:

export interface SomeType {
    foo: string
    bar: number
}

@foliet
Copy link
Contributor Author

foliet commented Oct 11, 2022

No need to define type in ts?

As a comparison, the past output is:

export interface SomeType {
    foo: string
    bar: number
}

image
This is the syntax feature of typescript, called union type
image
IDE can know which options are available for this variable

@kevwan kevwan merged commit 799c118 into zeromicro:master Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants