Skip to content

fix(typescript-angular): enable "exactOptionalPropertyTypes" and ensure assignments align with type definition#20451

Merged
macjohnny merged 5 commits intoOpenAPITools:masterfrom
jase88:fix/typescript-angular-exactOptionalPropertyTypes
Apr 23, 2025
Merged

fix(typescript-angular): enable "exactOptionalPropertyTypes" and ensure assignments align with type definition#20451
macjohnny merged 5 commits intoOpenAPITools:masterfrom
jase88:fix/typescript-angular-exactOptionalPropertyTypes

Conversation

@jase88
Copy link
Copy Markdown
Contributor

@jase88 jase88 commented Jan 12, 2025

fixes #20450

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)

@jase88
Copy link
Copy Markdown
Contributor Author

jase88 commented Apr 6, 2025

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)

When you have a moment, could you please take a look at my merge request and share your feedback? Thanks a lot!

responseType: <any>responseType_,
{{/isResponseFile}}
withCredentials: this.configuration.withCredentials,
...(withCredentials ? { withCredentials } : {}),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ?? Or || ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstand the suggestion to use the nullish coalescing operator, but if I use it I would have to specify a default value for withCredentials.

withCredentials is type of boolean and is optional, see here. With exactOptionalPropertyTypes an assignment of undefined wouldn't be allowed.

withCredentials: withCredentials ?? false seemed more like a breaking change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I would be fine to go this route. I had a rough look at the Angular code and it seems that no distinction is made between undefined and false.

if (configurationParameters.encodeParam) {
this.encodeParam = configurationParameters.encodeParam;
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: {{configurationParametersInterfaceName}} = {}) {
if (apiKeys) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all guarded now, but beforehand they weren't, if the containing object was truthy all of them would have been set, no matter if truthy or not. Do we need to look into it in more detail on whether that behavior changes are fully backwards compatible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is absolutely correct. I have adapted it by explicitly checking for undefined. The only exceptions are encoder and apiKeys, as both can only be of data type truthy or undefined.

@macjohnny
Copy link
Copy Markdown
Member

@joscha can you check whether this PR is ready? @jase88 can you fix the failing CI test?

Copy link
Copy Markdown
Contributor

@joscha joscha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a user of the angular variant, but I am happy with the answers from @jase88. If there are truthy/undefined issues further down, we can adjust the code.

@macjohnny macjohnny merged commit dfbe985 into OpenAPITools:master Apr 23, 2025
4 checks passed
@jase88 jase88 deleted the fix/typescript-angular-exactOptionalPropertyTypes branch April 26, 2025 16:45
@wing328 wing328 added this to the 7.13.0 milestone Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [typescript-angular] TypeScript compilers errors for generated code if configuration "exactOptionalPropertyTypes" is enabled

4 participants