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

[BUG] [typescript-angular] cannot compile with noUncheckedIndexedAccess set to true #18400

Closed
3 of 6 tasks
jase88 opened this issue Apr 16, 2024 · 0 comments · Fixed by #18457
Closed
3 of 6 tasks

[BUG] [typescript-angular] cannot compile with noUncheckedIndexedAccess set to true #18400

jase88 opened this issue Apr 16, 2024 · 0 comments · Fixed by #18457

Comments

@jase88
Copy link
Contributor

jase88 commented Apr 16, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

If noUncheckedIndexedAccess is set to true in tsconfig.json, the embedded openapi generated code doesn't compile.

constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string|string[], @Optional() configuration: Configuration) {
        ...
        if (typeof this.configuration.basePath !== 'string') {
            if (Array.isArray(basePath) && basePath.length > 0) {
                basePath = basePath[0];
            }

basePath is type of string|string[] and basePath[0] could be undefined. This is in a way a compiler weakness rather than an error, because the length of the array is checked beforehand, whose data type is string[].

openapi-generator version

7.2.0

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

could be set to basePath = basePath[0]!;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant